Skip to content

Commit 37d0a0e

Browse files
committed
add all missing api calls, this closes #2
1 parent e5b2fbb commit 37d0a0e

File tree

1 file changed

+120
-22
lines changed

1 file changed

+120
-22
lines changed

src/test/java/org/influxdb/InfluxDBTest.java

+120-22
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22

33
import java.util.List;
44
import java.util.concurrent.TimeUnit;
5+
import java.util.logging.Level;
6+
import java.util.logging.Logger;
57

68
import org.influxdb.InfluxDB.LogLevel;
79
import org.influxdb.dto.ContinuousQuery;
810
import org.influxdb.dto.Database;
911
import org.influxdb.dto.Pong;
10-
import org.influxdb.dto.ScheduledDelete;
1112
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;
1217
import org.influxdb.dto.User;
1318
import org.testng.Assert;
1419
import org.testng.annotations.AfterClass;
1520
import org.testng.annotations.BeforeClass;
1621
import org.testng.annotations.Test;
1722

23+
import com.google.common.collect.ImmutableList;
1824
import com.google.common.collect.Lists;
1925
import com.kpelykh.docker.client.DockerClient;
2026
import com.kpelykh.docker.client.DockerException;
@@ -45,6 +51,8 @@ public class InfluxDBTest {
4551
*/
4652
@BeforeClass
4753
public void setUp() throws DockerException, InterruptedException {
54+
// Disable logging for the DockerClient.
55+
Logger.getLogger("com.sun.jersey").setLevel(Level.OFF);
4856
this.dockerClient = new DockerClient("http://localhost:4243");
4957
this.dockerClient.pull("majst01/influxdb-java");
5058

@@ -71,7 +79,9 @@ public void setUp() throws DockerException, InterruptedException {
7179
Thread.sleep(100L);
7280
} while (!influxDBstarted);
7381
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("##################################################################################");
7585
}
7686

7787
/**
@@ -93,7 +103,7 @@ public void tearDown() throws DockerException {
93103
* Test for a ping.
94104
*/
95105
@Test
96-
public void pingTest() {
106+
public void testPing() {
97107
Pong result = this.influxDB.ping();
98108
Assert.assertNotNull(result);
99109
Assert.assertEquals(result.getStatus(), "ok");
@@ -103,7 +113,7 @@ public void pingTest() {
103113
* Test that describe Databases works.
104114
*/
105115
@Test
106-
public void describeDatabasesTest() {
116+
public void testDescribeDatabases() {
107117
String dbName = "unittest-" + System.currentTimeMillis();
108118
this.influxDB.createDatabase(dbName);
109119
List<Database> result = this.influxDB.describeDatabases();
@@ -123,7 +133,7 @@ public void describeDatabasesTest() {
123133
* Test that deletion of a Database works.
124134
*/
125135
@Test
126-
public void deleteDatabaseTest() {
136+
public void testDeleteDatabase() {
127137
List<Database> result = this.influxDB.describeDatabases();
128138
int databases = result.size();
129139
this.influxDB.createDatabase("toDelete");
@@ -144,7 +154,7 @@ public void deleteDatabaseTest() {
144154
* Test that writing of a simple Serie works.
145155
*/
146156
@Test
147-
public void writeTest() {
157+
public void testWrite() {
148158
String dbName = "write-unittest-" + System.currentTimeMillis();
149159
this.influxDB.createDatabase(dbName);
150160

@@ -162,7 +172,7 @@ public void writeTest() {
162172
*/
163173
// FIXME this test should be enabled.
164174
@Test(enabled = false)
165-
public void writeToNonExistingDatabaseTest() {
175+
public void testWriteToNonExistingDatabase() {
166176
Serie serie = new Serie.Builder("testSeries")
167177
.columns("value1", "value2")
168178
.values(System.currentTimeMillis(), 5)
@@ -177,7 +187,7 @@ public void writeToNonExistingDatabaseTest() {
177187
* Test for the new Serie.Builder.
178188
*/
179189
@Test
180-
public void writeWithSerieBuilder() {
190+
public void testWriteWithSerieBuilder() {
181191
String dbName = "writeseriebuilder-unittest-" + System.currentTimeMillis();
182192
this.influxDB.createDatabase(dbName);
183193
int outer = 20;
@@ -245,7 +255,7 @@ public void writeWithSerieBuilder() {
245255
* Test that querying works.
246256
*/
247257
@Test
248-
public void queryTest() {
258+
public void testQuery() {
249259
String dbName = "query-unittest-" + System.currentTimeMillis();
250260
this.influxDB.createDatabase(dbName);
251261

@@ -268,7 +278,7 @@ public void queryTest() {
268278
* Test that querying works.
269279
*/
270280
@Test
271-
public void complexQueryTest() {
281+
public void testComplexQuery() {
272282
String dbName = "complexquery-unittest-" + System.currentTimeMillis();
273283
this.influxDB.createDatabase(dbName);
274284

@@ -433,17 +443,6 @@ public void testContinuousQueries() {
433443
this.influxDB.deleteDatabase(dbName);
434444
}
435445

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-
447446
/**
448447
* Test that deletion of points works.
449448
*/
@@ -478,4 +477,103 @@ public void testVersion() {
478477
String version = this.influxDB.version();
479478
Assert.assertNotNull(version);
480479
}
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

Comments
 (0)