Search in sources :

Example 1 with RejectException

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);
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Reader(com.srotya.sidewinder.core.storage.compression.Reader) RejectException(com.srotya.sidewinder.core.storage.RejectException) GreaterThanEqualsPredicate(com.srotya.sidewinder.core.predicates.GreaterThanEqualsPredicate) ByteBuffer(java.nio.ByteBuffer) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) IOException(java.io.IOException) RejectException(com.srotya.sidewinder.core.storage.RejectException) RollOverException(com.srotya.sidewinder.core.storage.compression.RollOverException) Test(org.junit.Test)

Example 2 with RejectException

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) {
    }
}
Also used : RejectException(com.srotya.sidewinder.core.storage.RejectException) ByteBuffer(java.nio.ByteBuffer) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 3 with RejectException

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();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Reader(com.srotya.sidewinder.core.storage.compression.Reader) RejectException(com.srotya.sidewinder.core.storage.RejectException) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) RejectException(com.srotya.sidewinder.core.storage.RejectException) IOException(java.io.IOException) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) File(java.io.File) Test(org.junit.Test)

Example 4 with RejectException

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());
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Reader(com.srotya.sidewinder.core.storage.compression.Reader) RejectException(com.srotya.sidewinder.core.storage.RejectException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) RejectException(com.srotya.sidewinder.core.storage.RejectException) IOException(java.io.IOException) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point) Test(org.junit.Test)

Aggregations

DataPoint (com.srotya.sidewinder.core.storage.DataPoint)4 RejectException (com.srotya.sidewinder.core.storage.RejectException)4 Test (org.junit.Test)4 Reader (com.srotya.sidewinder.core.storage.compression.Reader)3 IOException (java.io.IOException)3 Point (com.srotya.sidewinder.core.rpc.Point)2 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)2 ByteBuffer (java.nio.ByteBuffer)2 GreaterThanEqualsPredicate (com.srotya.sidewinder.core.predicates.GreaterThanEqualsPredicate)1 RollOverException (com.srotya.sidewinder.core.storage.compression.RollOverException)1 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1