|
1 | 1 | package org.influxdb;
|
2 | 2 |
|
3 | 3 | import java.io.IOException;
|
| 4 | +import java.util.Arrays; |
4 | 5 | import java.util.List;
|
5 | 6 | import java.util.logging.Level;
|
6 | 7 | import java.util.logging.Logger;
|
@@ -184,6 +185,63 @@ public void testWrite() {
|
184 | 185 | this.influxDB.deleteDatabase(dbName);
|
185 | 186 | }
|
186 | 187 |
|
| 188 | + /** |
| 189 | + * Test writing to the database using string protocol. |
| 190 | + */ |
| 191 | + @Test(enabled = true) |
| 192 | + public void testWriteStringData() { |
| 193 | + String dbName = "write_unittest_" + System.currentTimeMillis(); |
| 194 | + this.influxDB.createDatabase(dbName); |
| 195 | + |
| 196 | + this.influxDB.write(dbName, "default", InfluxDB.ConsistencyLevel.ONE, "cpu,atag=test idle=90,usertime=9,system=1"); |
| 197 | + Query query = new Query("SELECT * FROM cpu GROUP BY *", dbName); |
| 198 | + QueryResult result = this.influxDB.query(query); |
| 199 | + Assert.assertFalse(result.getResults().get(0).getSeries().get(0).getTags().isEmpty()); |
| 200 | + this.influxDB.deleteDatabase(dbName); |
| 201 | + } |
| 202 | + |
| 203 | + /** |
| 204 | + * Test writing multiple records to the database using string protocol. |
| 205 | + */ |
| 206 | + @Test(enabled = true) |
| 207 | + public void testWriteMultipleStringData() { |
| 208 | + String dbName = "write_unittest_" + System.currentTimeMillis(); |
| 209 | + this.influxDB.createDatabase(dbName); |
| 210 | + |
| 211 | + this.influxDB.write(dbName, "default", InfluxDB.ConsistencyLevel.ONE, "cpu,atag=test1 idle=100,usertime=10,system=1\ncpu,atag=test2 idle=200,usertime=20,system=2\ncpu,atag=test3 idle=300,usertime=30,system=3"); |
| 212 | + Query query = new Query("SELECT * FROM cpu GROUP BY *", dbName); |
| 213 | + QueryResult result = this.influxDB.query(query); |
| 214 | + |
| 215 | + Assert.assertEquals(result.getResults().get(0).getSeries().size(), 3); |
| 216 | + Assert.assertEquals(result.getResults().get(0).getSeries().get(0).getTags().get("atag"), "test1"); |
| 217 | + Assert.assertEquals(result.getResults().get(0).getSeries().get(1).getTags().get("atag"), "test2"); |
| 218 | + Assert.assertEquals(result.getResults().get(0).getSeries().get(2).getTags().get("atag"), "test3"); |
| 219 | + this.influxDB.deleteDatabase(dbName); |
| 220 | + } |
| 221 | + |
| 222 | + /** |
| 223 | + * Test writing multiple separate records to the database using string protocol. |
| 224 | + */ |
| 225 | + @Test(enabled = true) |
| 226 | + public void testWriteMultipleStringDataLines() { |
| 227 | + String dbName = "write_unittest_" + System.currentTimeMillis(); |
| 228 | + this.influxDB.createDatabase(dbName); |
| 229 | + |
| 230 | + this.influxDB.write(dbName, "default", InfluxDB.ConsistencyLevel.ONE, Arrays.asList( |
| 231 | + "cpu,atag=test1 idle=100,usertime=10,system=1", |
| 232 | + "cpu,atag=test2 idle=200,usertime=20,system=2", |
| 233 | + "cpu,atag=test3 idle=300,usertime=30,system=3" |
| 234 | + )); |
| 235 | + Query query = new Query("SELECT * FROM cpu GROUP BY *", dbName); |
| 236 | + QueryResult result = this.influxDB.query(query); |
| 237 | + |
| 238 | + Assert.assertEquals(result.getResults().get(0).getSeries().size(), 3); |
| 239 | + Assert.assertEquals(result.getResults().get(0).getSeries().get(0).getTags().get("atag"), "test1"); |
| 240 | + Assert.assertEquals(result.getResults().get(0).getSeries().get(1).getTags().get("atag"), "test2"); |
| 241 | + Assert.assertEquals(result.getResults().get(0).getSeries().get(2).getTags().get("atag"), "test3"); |
| 242 | + this.influxDB.deleteDatabase(dbName); |
| 243 | + } |
| 244 | + |
187 | 245 | /**
|
188 | 246 | * Test that creating database which name is composed of numbers only works
|
189 | 247 | */
|
|
0 commit comments