use of com.srotya.sidewinder.core.predicates.GreaterThanEqualsPredicate in project sidewinder by srotya.
the class TestByzantineReadWrite method testPredicateFilter.
@Test
public void testPredicateFilter() throws IOException {
ByteBuffer buf = ByteBuffer.allocateDirect(1024 * 1024 * 10);
ByzantineWriter writer = new ByzantineWriter();
writer.configure(new HashMap<>(), buf, true, startOffset, true);
long ots = System.currentTimeMillis();
writer.setHeaderTimestamp(ots);
int limit = 1_000_000;
for (int i = 0; i < limit; i++) {
writer.addValue(ots + i * 1000, i);
}
Reader reader = writer.getReader();
reader.setTimePredicate(new GreaterThanEqualsPredicate(ots + 1000));
int c = 0;
assertEquals(limit, reader.getPairCount());
try {
for (int i = 0; i < limit; i++) {
DataPoint pair = reader.readPair();
if (pair != null) {
assertEquals(ots + i * 1000, pair.getTimestamp());
assertEquals(i, pair.getLongValue());
c++;
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
assertEquals(limit - 1, c);
reader = writer.getReader();
reader.setValuePredicate(new GreaterThanEqualsPredicate(1000));
c = 0;
assertEquals(limit, reader.getPairCount());
try {
for (int i = 0; i < limit; i++) {
DataPoint pair = reader.readPair();
if (pair != null) {
assertEquals(ots + i * 1000, pair.getTimestamp());
assertEquals(i, pair.getLongValue());
c++;
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
try {
reader.readPair();
fail("Must throw end of stream exception");
} catch (RejectException e) {
}
try {
reader.read();
fail("Must throw end of stream exception");
} catch (RejectException e) {
}
assertEquals(limit - 1000, c);
assertEquals(limit, reader.getCounter());
reader = writer.getReader();
reader.setTimePredicate(new GreaterThanEqualsPredicate(ots + 1000));
c = 0;
assertEquals(limit, reader.getPairCount());
try {
for (int i = 0; i < limit; i++) {
long[] pair = reader.read();
if (pair != null) {
assertEquals(ots + i * 1000, pair[0]);
assertEquals(i, pair[1]);
c++;
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
assertEquals(limit - 1, c);
reader = writer.getReader();
reader.setValuePredicate(new GreaterThanEqualsPredicate(1000));
c = 0;
assertEquals(limit, reader.getPairCount());
try {
for (int i = 0; i < limit; i++) {
long[] pair = reader.read();
if (pair != null) {
assertEquals(ots + i * 1000, pair[0]);
assertEquals(i, pair[1]);
c++;
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
assertEquals(limit - 1000, c);
}
Aggregations