33import org .testng .annotations .Test ;
44import static org .assertj .core .api .Assertions .*;
55
6+ import java .math .BigDecimal ;
7+ import java .math .BigInteger ;
68import java .util .concurrent .TimeUnit ;
9+ import java .util .concurrent .atomic .AtomicInteger ;
10+ import java .util .concurrent .atomic .AtomicLong ;
711
812/**
913 * Test for the Point DTO.
@@ -22,10 +26,10 @@ public class PointTest {
2226 @ Test
2327 public void lineProtocol () {
2428 Point point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , 1 ).build ();
25- assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=1 1" );
29+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=1.0 1" );
2630
2731 point = Point .measurement ("test,1" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , 1 ).build ();
28- assertThat (point .lineProtocol ()).asString ().isEqualTo ("test\\ ,1 a=1 1" );
32+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test\\ ,1 a=1.0 1" );
2933
3034 point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , "A" ).build ();
3135 assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=\" A\" 1" );
@@ -48,4 +52,81 @@ public void lineProtocol() {
4852 assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=\" A\\ \" B\" ,b=\" D E \\ \" F\" 1" );
4953
5054 }
55+
56+ /**
57+ * Test for ticket #44
58+ */
59+ @ Test (enabled = true )
60+ public void testTicket44 () {
61+ Point point = Point .measurement ("test" ).time (1 , TimeUnit .MICROSECONDS ).field ("a" , 1 ).build ();
62+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=1.0 1000" );
63+
64+ point = Point .measurement ("test" ).time (1 , TimeUnit .MILLISECONDS ).field ("a" , 1 ).build ();
65+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=1.0 1000000" );
66+
67+ point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , 1 ).build ();
68+ BatchPoints batchPoints = BatchPoints .database ("db" ).point (point ).build ();
69+ assertThat (batchPoints .lineProtocol ()).asString ().isEqualTo ("test a=1.0 1\n " );
70+
71+ point = Point .measurement ("test" ).time (1 , TimeUnit .MICROSECONDS ).field ("a" , 1 ).build ();
72+ batchPoints = BatchPoints .database ("db" ).point (point ).build ();
73+ assertThat (batchPoints .lineProtocol ()).asString ().isEqualTo ("test a=1.0 1000\n " );
74+
75+ point = Point .measurement ("test" ).time (1 , TimeUnit .MILLISECONDS ).field ("a" , 1 ).build ();
76+ batchPoints = BatchPoints .database ("db" ).point (point ).build ();
77+ assertThat (batchPoints .lineProtocol ()).asString ().isEqualTo ("test a=1.0 1000000\n " );
78+
79+ point = Point .measurement ("test" ).field ("a" , 1 ).time (1 , TimeUnit .MILLISECONDS ).build ();
80+ batchPoints = BatchPoints .database ("db" ).build ();
81+ batchPoints = batchPoints .point (point );
82+ assertThat (batchPoints .lineProtocol ()).asString ().isEqualTo ("test a=1.0 1000000\n " );
83+
84+ }
85+
86+ /**
87+ * Test for ticket #54
88+ */
89+ @ Test
90+ public void testTicket54 () {
91+ Byte byteNumber = 100 ;
92+ Point point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , byteNumber ).build ();
93+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=100.0 1" );
94+
95+ int intNumber = 100000000 ;
96+ point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , intNumber ).build ();
97+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=100000000.0 1" );
98+
99+ Integer integerNumber = 100000000 ;
100+ point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , integerNumber ).build ();
101+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=100000000.0 1" );
102+
103+ AtomicInteger atomicIntegerNumber = new AtomicInteger (100000000 );
104+ point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , atomicIntegerNumber ).build ();
105+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=100000000.0 1" );
106+
107+ Long longNumber = 1000000000000000000L ;
108+ point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , longNumber ).build ();
109+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=1000000000000000000.0 1" );
110+
111+ AtomicLong atomicLongNumber = new AtomicLong (1000000000000000000L );
112+ point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , atomicLongNumber ).build ();
113+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=1000000000000000000.0 1" );
114+
115+ BigInteger bigIntegerNumber = BigInteger .valueOf (100000000 );
116+ point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , bigIntegerNumber ).build ();
117+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=100000000.0 1" );
118+
119+ Double doubleNumber = Double .valueOf (100000000.0001 );
120+ point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , doubleNumber ).build ();
121+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=100000000.0001 1" );
122+
123+ Float floatNumber = Float .valueOf (0.1f );
124+ point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , floatNumber ).build ();
125+ assertThat (point .lineProtocol ()).asString ().startsWith ("test a=0.10" );
126+
127+ BigDecimal bigDecimalNumber = BigDecimal .valueOf (100000000.00000001 );
128+ point = Point .measurement ("test" ).time (1 , TimeUnit .NANOSECONDS ).field ("a" , bigDecimalNumber ).build ();
129+ assertThat (point .lineProtocol ()).asString ().isEqualTo ("test a=100000000.00000001 1" );
130+ }
131+
51132}
0 commit comments