|
|
@@ -189,7 +189,28 @@ class TestClient(object): |
|
|
|
result = client.stream_insert("/newton/prep", data) |
|
|
|
eq_(result, None) |
|
|
|
|
|
|
|
# Try forcing a server request with empty data |
|
|
|
# It's OK to insert an empty interval |
|
|
|
client.http.put("stream/insert", "", { "path": "/newton/prep", |
|
|
|
"start": 1, "end": 2 }) |
|
|
|
eq_(list(client.stream_intervals("/newton/prep")), [[1, 2]]) |
|
|
|
client.stream_remove("/newton/prep") |
|
|
|
eq_(list(client.stream_intervals("/newton/prep")), []) |
|
|
|
|
|
|
|
# Timestamps can be negative too |
|
|
|
client.http.put("stream/insert", "", { "path": "/newton/prep", |
|
|
|
"start": -2, "end": -1 }) |
|
|
|
eq_(list(client.stream_intervals("/newton/prep")), [[-2, -1]]) |
|
|
|
client.stream_remove("/newton/prep") |
|
|
|
eq_(list(client.stream_intervals("/newton/prep")), []) |
|
|
|
|
|
|
|
# Intervals that end at zero shouldn't be any different |
|
|
|
client.http.put("stream/insert", "", { "path": "/newton/prep", |
|
|
|
"start": -1, "end": 0 }) |
|
|
|
eq_(list(client.stream_intervals("/newton/prep")), [[-1, 0]]) |
|
|
|
client.stream_remove("/newton/prep") |
|
|
|
eq_(list(client.stream_intervals("/newton/prep")), []) |
|
|
|
|
|
|
|
# Try forcing a server request with equal start and end |
|
|
|
with assert_raises(ClientError) as e: |
|
|
|
client.http.put("stream/insert", "", { "path": "/newton/prep", |
|
|
|
"start": 0, "end": 0 }) |
|
|
@@ -469,3 +490,89 @@ class TestClient(object): |
|
|
|
|
|
|
|
client.stream_destroy("/context/test") |
|
|
|
client.close() |
|
|
|
|
|
|
|
def test_client_11_emptyintervals(self): |
|
|
|
# Empty intervals are ok! If recording detection events |
|
|
|
# by inserting rows into the database, we want to be able to |
|
|
|
# have an interval where no events occurred. Test them here. |
|
|
|
client = nilmdb.Client(testurl) |
|
|
|
client.stream_create("/empty/test", "uint16_1") |
|
|
|
|
|
|
|
def info(): |
|
|
|
result = [] |
|
|
|
for interval in list(client.stream_intervals("/empty/test")): |
|
|
|
result.append((client.stream_count("/empty/test", *interval), |
|
|
|
interval)) |
|
|
|
return result |
|
|
|
|
|
|
|
eq_(info(), []) |
|
|
|
|
|
|
|
# Insert a region with just a few points |
|
|
|
with client.stream_insert_context("/empty/test") as ctx: |
|
|
|
ctx.update_start(100) |
|
|
|
ctx.insert_line("140 1\n") |
|
|
|
ctx.insert_line("150 1\n") |
|
|
|
ctx.insert_line("160 1\n") |
|
|
|
ctx.update_end(200) |
|
|
|
ctx.finalize() |
|
|
|
|
|
|
|
eq_(info(), [(3, [100, 200])]) |
|
|
|
|
|
|
|
# Delete chunk, which will leave one data point and two intervals |
|
|
|
client.stream_remove("/empty/test", 145, 175) |
|
|
|
eq_(info(), [(1, [100, 145]), |
|
|
|
(0, [175, 200])]) |
|
|
|
|
|
|
|
# Try also creating a completely empty interval from scratch, |
|
|
|
# in a few different ways. |
|
|
|
client.stream_insert_block("/empty/test", "", 300, 350) |
|
|
|
client.stream_insert("/empty/test", [], 400, 450) |
|
|
|
with client.stream_insert_context("/empty/test", 500, 550): |
|
|
|
pass |
|
|
|
|
|
|
|
# If enough timestamps aren't provided, empty streams won't be created. |
|
|
|
client.stream_insert("/empty/test", []) |
|
|
|
with client.stream_insert_context("/empty/test"): |
|
|
|
pass |
|
|
|
client.stream_insert("/empty/test", [], start = 600) |
|
|
|
with client.stream_insert_context("/empty/test", start = 700): |
|
|
|
pass |
|
|
|
client.stream_insert("/empty/test", [], end = 850) |
|
|
|
with client.stream_insert_context("/empty/test", end = 950): |
|
|
|
pass |
|
|
|
|
|
|
|
# Try various things that might cause problems |
|
|
|
with client.stream_insert_context("/empty/test", 1000, 1050): |
|
|
|
ctx.finalize() # inserts [1000, 1050] |
|
|
|
ctx.finalize() # nothing |
|
|
|
ctx.finalize() # nothing |
|
|
|
ctx.insert_line("1100 1\n") |
|
|
|
ctx.finalize() # inserts [1100, 1100.000001] |
|
|
|
ctx.update_start(1199) |
|
|
|
ctx.insert_line("1200 1\n") |
|
|
|
ctx.update_end(1250) |
|
|
|
ctx.finalize() # inserts [1199, 1250] |
|
|
|
ctx.update_start(1299) |
|
|
|
ctx.finalize() # nothing |
|
|
|
ctx.update_end(1350) |
|
|
|
ctx.finalize() # nothing |
|
|
|
ctx.update_start(1400) |
|
|
|
ctx.update_end(1450) |
|
|
|
ctx.finalize() |
|
|
|
# implicit last finalize inserts [1400, 1450] |
|
|
|
|
|
|
|
# Check everything |
|
|
|
eq_(info(), [(1, [100, 145]), |
|
|
|
(0, [175, 200]), |
|
|
|
(0, [300, 350]), |
|
|
|
(0, [400, 450]), |
|
|
|
(0, [500, 550]), |
|
|
|
(0, [1000, 1050]), |
|
|
|
(1, [1100, 1100.000001]), |
|
|
|
(1, [1199, 1250]), |
|
|
|
(0, [1400, 1450]), |
|
|
|
]) |
|
|
|
|
|
|
|
# Clean up |
|
|
|
client.stream_destroy("/empty/test") |
|
|
|
client.close() |