use of com.srotya.sidewinder.core.storage.RejectException 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);
}
use of com.srotya.sidewinder.core.storage.RejectException in project sidewinder by srotya.
the class TestByzantineReadWrite method testWriteReject.
@Test
public void testWriteReject() 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);
}
writer.makeReadOnly();
try {
writer.addValue(ots, 2L);
fail("Must throw exception once the buffer is marked as closed");
} catch (RejectException e) {
}
}
use of com.srotya.sidewinder.core.storage.RejectException in project sidewinder by srotya.
the class TestDiskStorageEngine method testAddAndReaderDataPoints.
@Test
public void testAddAndReaderDataPoints() throws Exception {
DiskStorageEngine engine = new DiskStorageEngine();
File file = new File("target/db8/");
if (file.exists()) {
MiscUtils.delete(file);
}
HashMap<String, String> map = new HashMap<>();
map.put("metadata.dir", "target/db8/mdq");
map.put("index.dir", "target/db8/index");
map.put("data.dir", "target/db8/data");
map.put(StorageEngine.PERSISTENCE_DISK, "true");
engine.configure(map, bgTasks);
long curr = 1497720452566L;
String dbName = "test";
String measurementName = "cpu";
String valueFieldName = "value";
try {
engine.writeDataPoint(MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, null, curr, 2.2 * 0));
fail("Must reject the above datapoint due to missing tags");
} catch (Exception e) {
}
for (int i = 1; i <= 3; i++) {
engine.writeDataPoint(MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, Arrays.asList(dbName + "=1"), curr + i, 2.2 * i));
}
assertEquals(1, engine.getAllMeasurementsForDb(dbName).size());
LinkedHashMap<Reader, Boolean> readers = engine.queryReaders(dbName, measurementName, valueFieldName, curr, curr + 3);
int count = 0;
for (Entry<Reader, Boolean> entry : readers.entrySet()) {
assertTrue(entry.getValue());
while (true) {
try {
DataPoint readPair = entry.getKey().readPair();
assertEquals(2.2 * (count + 1), readPair.getValue(), 0.01);
count++;
} catch (RejectException e) {
break;
}
}
}
assertEquals(3, count);
assertTrue(engine.checkIfExists(dbName, measurementName));
try {
engine.checkIfExists(dbName + "1");
} catch (Exception e) {
}
engine.dropMeasurement(dbName, measurementName);
assertEquals(0, engine.getAllMeasurementsForDb(dbName).size());
engine.disconnect();
}
use of com.srotya.sidewinder.core.storage.RejectException in project sidewinder by srotya.
the class TestMemStorageEngine method testAddAndReaderDataPoints.
@Test
public void testAddAndReaderDataPoints() throws Exception {
MemStorageEngine engine = new MemStorageEngine();
engine.configure(new HashMap<>(), bgTasks);
long curr = System.currentTimeMillis();
String dbName = "test";
String measurementName = "cpu";
String valueFieldName = "value";
try {
engine.writeDataPoint(MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, null, curr, 2.2 * 0));
fail("Must reject the above datapoint due to missing tags");
} catch (Exception e) {
}
for (int i = 1; i <= 3; i++) {
engine.writeDataPoint(MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, Arrays.asList(dbName + "=2"), curr + i, 2.2 * i));
}
assertEquals(1, engine.getAllMeasurementsForDb(dbName).size());
LinkedHashMap<Reader, Boolean> readers = engine.queryReaders(dbName, measurementName, valueFieldName, curr, curr + 3);
int count = 0;
for (Entry<Reader, Boolean> entry : readers.entrySet()) {
assertTrue(entry.getValue());
while (true) {
try {
DataPoint readPair = entry.getKey().readPair();
assertEquals(2.2 * (count + 1), readPair.getValue(), 0.01);
count++;
} catch (RejectException e) {
break;
}
}
}
assertEquals(3, count);
assertTrue(engine.checkIfExists(dbName, measurementName));
try {
engine.checkIfExists(dbName + "1");
} catch (Exception e) {
}
engine.dropMeasurement(dbName, measurementName);
assertEquals(0, engine.getAllMeasurementsForDb(dbName).size());
}
Aggregations