2
2
3
3
import java .util .List ;
4
4
import java .util .concurrent .TimeUnit ;
5
+ import java .util .logging .Level ;
6
+ import java .util .logging .Logger ;
5
7
6
8
import org .influxdb .InfluxDB .LogLevel ;
7
9
import org .influxdb .dto .ContinuousQuery ;
8
10
import org .influxdb .dto .Database ;
9
11
import org .influxdb .dto .Pong ;
10
- import org .influxdb .dto .ScheduledDelete ;
11
12
import org .influxdb .dto .Serie ;
13
+ import org .influxdb .dto .Server ;
14
+ import org .influxdb .dto .Shard ;
15
+ import org .influxdb .dto .Shard .Member ;
16
+ import org .influxdb .dto .Shards ;
12
17
import org .influxdb .dto .User ;
13
18
import org .testng .Assert ;
14
19
import org .testng .annotations .AfterClass ;
15
20
import org .testng .annotations .BeforeClass ;
16
21
import org .testng .annotations .Test ;
17
22
23
+ import com .google .common .collect .ImmutableList ;
18
24
import com .google .common .collect .Lists ;
19
25
import com .kpelykh .docker .client .DockerClient ;
20
26
import com .kpelykh .docker .client .DockerException ;
@@ -45,6 +51,8 @@ public class InfluxDBTest {
45
51
*/
46
52
@ BeforeClass
47
53
public void setUp () throws DockerException , InterruptedException {
54
+ // Disable logging for the DockerClient.
55
+ Logger .getLogger ("com.sun.jersey" ).setLevel (Level .OFF );
48
56
this .dockerClient = new DockerClient ("http://localhost:4243" );
49
57
this .dockerClient .pull ("majst01/influxdb-java" );
50
58
@@ -71,7 +79,9 @@ public void setUp() throws DockerException, InterruptedException {
71
79
Thread .sleep (100L );
72
80
} while (!influxDBstarted );
73
81
this .influxDB .setLogLevel (LogLevel .NONE );
74
- System .out .println ("Connected to InfluxDB Version: " + this .influxDB .version ());
82
+ System .out .println ("##################################################################################" );
83
+ System .out .println ("# Connected to InfluxDB Version: " + this .influxDB .version () + " #" );
84
+ System .out .println ("##################################################################################" );
75
85
}
76
86
77
87
/**
@@ -93,7 +103,7 @@ public void tearDown() throws DockerException {
93
103
* Test for a ping.
94
104
*/
95
105
@ Test
96
- public void pingTest () {
106
+ public void testPing () {
97
107
Pong result = this .influxDB .ping ();
98
108
Assert .assertNotNull (result );
99
109
Assert .assertEquals (result .getStatus (), "ok" );
@@ -103,7 +113,7 @@ public void pingTest() {
103
113
* Test that describe Databases works.
104
114
*/
105
115
@ Test
106
- public void describeDatabasesTest () {
116
+ public void testDescribeDatabases () {
107
117
String dbName = "unittest-" + System .currentTimeMillis ();
108
118
this .influxDB .createDatabase (dbName );
109
119
List <Database > result = this .influxDB .describeDatabases ();
@@ -123,7 +133,7 @@ public void describeDatabasesTest() {
123
133
* Test that deletion of a Database works.
124
134
*/
125
135
@ Test
126
- public void deleteDatabaseTest () {
136
+ public void testDeleteDatabase () {
127
137
List <Database > result = this .influxDB .describeDatabases ();
128
138
int databases = result .size ();
129
139
this .influxDB .createDatabase ("toDelete" );
@@ -144,7 +154,7 @@ public void deleteDatabaseTest() {
144
154
* Test that writing of a simple Serie works.
145
155
*/
146
156
@ Test
147
- public void writeTest () {
157
+ public void testWrite () {
148
158
String dbName = "write-unittest-" + System .currentTimeMillis ();
149
159
this .influxDB .createDatabase (dbName );
150
160
@@ -162,7 +172,7 @@ public void writeTest() {
162
172
*/
163
173
// FIXME this test should be enabled.
164
174
@ Test (enabled = false )
165
- public void writeToNonExistingDatabaseTest () {
175
+ public void testWriteToNonExistingDatabase () {
166
176
Serie serie = new Serie .Builder ("testSeries" )
167
177
.columns ("value1" , "value2" )
168
178
.values (System .currentTimeMillis (), 5 )
@@ -177,7 +187,7 @@ public void writeToNonExistingDatabaseTest() {
177
187
* Test for the new Serie.Builder.
178
188
*/
179
189
@ Test
180
- public void writeWithSerieBuilder () {
190
+ public void testWriteWithSerieBuilder () {
181
191
String dbName = "writeseriebuilder-unittest-" + System .currentTimeMillis ();
182
192
this .influxDB .createDatabase (dbName );
183
193
int outer = 20 ;
@@ -245,7 +255,7 @@ public void writeWithSerieBuilder() {
245
255
* Test that querying works.
246
256
*/
247
257
@ Test
248
- public void queryTest () {
258
+ public void testQuery () {
249
259
String dbName = "query-unittest-" + System .currentTimeMillis ();
250
260
this .influxDB .createDatabase (dbName );
251
261
@@ -268,7 +278,7 @@ public void queryTest() {
268
278
* Test that querying works.
269
279
*/
270
280
@ Test
271
- public void complexQueryTest () {
281
+ public void testComplexQuery () {
272
282
String dbName = "complexquery-unittest-" + System .currentTimeMillis ();
273
283
this .influxDB .createDatabase (dbName );
274
284
@@ -433,17 +443,6 @@ public void testContinuousQueries() {
433
443
this .influxDB .deleteDatabase (dbName );
434
444
}
435
445
436
- /**
437
- * Test is disabled because this is not implemented in influxDB.
438
- */
439
- @ Test (enabled = false )
440
- public void testCreateDeleteDescribeScheduledDeletes () {
441
- String dbName = "scheduleddeletes-unittest-" + System .currentTimeMillis ();
442
- List <ScheduledDelete > deletes = this .influxDB .describeScheduledDeletes (dbName );
443
- Assert .assertNull (deletes );
444
- Assert .assertEquals (deletes .size (), 0 );
445
- }
446
-
447
446
/**
448
447
* Test that deletion of points works.
449
448
*/
@@ -478,4 +477,103 @@ public void testVersion() {
478
477
String version = this .influxDB .version ();
479
478
Assert .assertNotNull (version );
480
479
}
481
- }
480
+
481
+ /**
482
+ * Test that compaction works.
483
+ */
484
+ @ Test
485
+ public void testForceRaftCompaction () {
486
+ this .influxDB .forceRaftCompaction ();
487
+ }
488
+
489
+ /**
490
+ * Test that list interfaces works.
491
+ */
492
+ @ Test
493
+ public void testInterfaces () {
494
+ List <String > interfaces = this .influxDB .interfaces ();
495
+ Assert .assertNotNull (interfaces );
496
+ Assert .assertTrue (interfaces .size () > 0 );
497
+ Assert .assertEquals (interfaces .get (0 ), "default" );
498
+ }
499
+
500
+ /**
501
+ * Test that sync works.
502
+ */
503
+ @ Test
504
+ public void testSync () {
505
+ Boolean executed = this .influxDB .sync ();
506
+ Assert .assertTrue (executed );
507
+ }
508
+
509
+ /**
510
+ * Test that list servers works.
511
+ */
512
+ @ Test
513
+ public void testListServers () {
514
+ List <Server > servers = this .influxDB .listServers ();
515
+ Assert .assertNotNull (servers );
516
+ Assert .assertTrue (servers .size () > 0 );
517
+ Assert .assertEquals (servers .get (0 ).getId (), 1 );
518
+ }
519
+
520
+ /**
521
+ * Test that remove servers works.
522
+ */
523
+ @ Test
524
+ public void testRemoveServers () {
525
+ this .influxDB .removeServers (2 );
526
+ }
527
+
528
+ /**
529
+ * Test that describe, create and drop of shards works.
530
+ *
531
+ * @throws InterruptedException
532
+ */
533
+ @ Test
534
+ public void testDescribeCreateDropShard () throws InterruptedException {
535
+ Shards existingShards = this .influxDB .getShards ();
536
+ Assert .assertNotNull (existingShards );
537
+ Assert .assertNotNull (existingShards .getLongTerm ());
538
+ Assert .assertNotNull (existingShards .getShortTerm ());
539
+ int existingLongTermShards = existingShards .getLongTerm ().size ();
540
+ int existingShortTermShards = existingShards .getShortTerm ().size ();
541
+
542
+ Shard shard = new Shard ();
543
+ long now = System .currentTimeMillis () / 1000L ;
544
+ shard .setStartTime (now );
545
+ shard .setEndTime (now + 10000L );
546
+ shard .setLongTerm (false );
547
+ Member shards = new Member ();
548
+ shards .setServerIds (ImmutableList .of (1 ));
549
+ shard .setShards (ImmutableList .of (shards ));
550
+ this .influxDB .createShard (shard );
551
+
552
+ Shard shard2 = new Shard ();
553
+ shard .setStartTime (now );
554
+ shard .setEndTime (now + 10000L );
555
+ shard .setLongTerm (false );
556
+ Member shards2 = new Member ();
557
+ shards2 .setServerIds (ImmutableList .of (1 ));
558
+ shard2 .setShards (ImmutableList .of (shards2 ));
559
+ this .influxDB .createShard (shard2 );
560
+
561
+ Shards createdShards = this .influxDB .getShards ();
562
+
563
+ Assert .assertNotNull (createdShards );
564
+ Assert .assertNotNull (createdShards .getLongTerm ());
565
+ Assert .assertNotNull (createdShards .getShortTerm ());
566
+ Assert .assertEquals (createdShards .getShortTerm ().size (), existingShortTermShards + 2 );
567
+ Assert .assertEquals (createdShards .getLongTerm ().size (), existingLongTermShards );
568
+
569
+ shard .setId (2 );
570
+ shard2 .setId (3 );
571
+ this .influxDB .dropShard (shard );
572
+ existingShards = this .influxDB .getShards ();
573
+ Assert .assertEquals (existingShards .getShortTerm ().size (), existingShortTermShards + 1 );
574
+ this .influxDB .dropShard (shard2 );
575
+ existingShards = this .influxDB .getShards ();
576
+ Assert .assertEquals (existingShards .getShortTerm ().size (), existingShortTermShards );
577
+ }
578
+
579
+ }
0 commit comments