From 2d1c9bc226a9266e2200eb6c3d7c27a810b5fb15 Mon Sep 17 00:00:00 2001 From: Hoan Xuan Le Date: Wed, 25 Jul 2018 13:26:35 +0700 Subject: [PATCH] issue #468 tags should be sorted by key in line protocol to reduce db server overheads add unit test --- src/test/java/org/influxdb/dto/PointTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/org/influxdb/dto/PointTest.java b/src/test/java/org/influxdb/dto/PointTest.java index 7d1a72ccc..ce7ffd08a 100644 --- a/src/test/java/org/influxdb/dto/PointTest.java +++ b/src/test/java/org/influxdb/dto/PointTest.java @@ -450,4 +450,31 @@ public void testLineProtocolHourPrecision() throws Exception { String expectedHourTimeStamp = String.valueOf(Math.round(pDate.getTime() / 3600000)); // 1000ms * 60s * 60m assertThat(hourTime).isEqualTo(expectedHourTimeStamp); } + + /* + * Test if representation of tags in line protocol format should be sorted by tag key + */ + @Test + public void testTagKeyIsSortedInLineProtocol() { + Point p = Point + .measurement("cpu") + .time(1000000000L, TimeUnit.MILLISECONDS) + .addField("value", 1) + .tag("region", "us-west") + .tag("host", "serverA") + .tag("env", "prod") + .tag("target", "servers") + .tag("zone", "1c") + .tag("tag5", "value5") + .tag("tag1", "value1") + .tag("tag2", "value2") + .tag("tag3", "value3") + .tag("tag4", "value4") + .build(); + + String lineProtocol = p.lineProtocol(); + String correctOrder = "env=prod,host=serverA,region=us-west,tag1=value1,tag2=value2,tag3=value3,tag4=value4,tag5=value5,target=servers,zone=1c"; + String tags = lineProtocol.substring(lineProtocol.indexOf(',') + 1, lineProtocol.indexOf(' ')); + assertThat(tags).isEqualTo(correctOrder); + } }