Search in sources :

Example 11 with StorageEngine

use of com.srotya.sidewinder.core.storage.StorageEngine in project sidewinder by srotya.

the class TestDiskStorageEngine method testConfigure.

@Test
public void testConfigure() throws IOException {
    StorageEngine engine = new DiskStorageEngine();
    try {
        engine.writeDataPoint(MiscUtils.buildDataPoint("test", "ss", "value", Arrays.asList("t=e"), System.currentTimeMillis(), 2.2));
        fail("Engine not initialized, shouldn't be able to write a datapoint");
    } catch (Exception e) {
    }
    try {
        // FileUtils.forceDelete(new File("target/db2/"));
        MiscUtils.delete(new File("targer/db2/"));
        HashMap<String, String> map = new HashMap<>();
        // map.put("metadata.dir", "target/db2/mdq");
        map.put("index.dir", "target/db2/index");
        map.put("data.dir", "target/db2/data");
        map.put(StorageEngine.PERSISTENCE_DISK, "true");
        map.put("default.series.retention.hours", "32");
        engine.configure(map, bgTasks);
    } catch (IOException e) {
        fail("No IOException should be thrown");
    }
    try {
        engine.writeDataPoint(MiscUtils.buildDataPoint("test", "ss", "value", Arrays.asList("t=e"), System.currentTimeMillis(), 2.2));
        String md = new String(Files.readAllBytes(new File("target/db2/data/test/.md").toPath()), Charset.forName("utf8"));
        DBMetadata metadata = new Gson().fromJson(md, DBMetadata.class);
        assertEquals(32, metadata.getRetentionHours());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Engine is initialized, no IO Exception should be thrown:" + e.getMessage());
    }
    engine.disconnect();
}
Also used : DBMetadata(com.srotya.sidewinder.core.storage.DBMetadata) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Gson(com.google.gson.Gson) IOException(java.io.IOException) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) File(java.io.File) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) RejectException(com.srotya.sidewinder.core.storage.RejectException) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with StorageEngine

use of com.srotya.sidewinder.core.storage.StorageEngine in project sidewinder by srotya.

the class TestDiskStorageEngine method testGetMeasurementsLike.

@Test
public void testGetMeasurementsLike() throws Exception {
    StorageEngine engine = new DiskStorageEngine();
    MiscUtils.delete(new File("target/db1/"));
    HashMap<String, String> map = new HashMap<>();
    map.put("metadata.dir", "target/db1/mdq");
    map.put("index.dir", "target/db1/index");
    map.put("data.dir", "target/db1/data");
    map.put(StorageEngine.PERSISTENCE_DISK, "true");
    engine.configure(map, bgTasks);
    engine.writeDataPoint(MiscUtils.buildDataPoint("test", "cpu", "value", Arrays.asList("test=1"), System.currentTimeMillis(), 2L));
    engine.writeDataPoint(MiscUtils.buildDataPoint("test", "mem", "value", Arrays.asList("test=1"), System.currentTimeMillis() + 10, 3L));
    engine.writeDataPoint(MiscUtils.buildDataPoint("test", "netm", "value", Arrays.asList("test=1"), System.currentTimeMillis() + 20, 5L));
    Set<String> result = engine.getMeasurementsLike("test", " ");
    assertEquals(3, result.size());
    result = engine.getMeasurementsLike("test", "c.*");
    assertEquals(1, result.size());
    result = engine.getMeasurementsLike("test", ".*m.*");
    assertEquals(2, result.size());
    engine.disconnect();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) File(java.io.File) Test(org.junit.Test)

Example 13 with StorageEngine

use of com.srotya.sidewinder.core.storage.StorageEngine in project sidewinder by srotya.

the class TestMemStorageEngine method testConfigureTimeBuckets.

@Test
public void testConfigureTimeBuckets() throws ItemNotFoundException, IOException {
    StorageEngine engine = new MemStorageEngine();
    HashMap<String, String> conf = new HashMap<>();
    long ts = System.currentTimeMillis();
    conf.put(StorageEngine.DEFAULT_BUCKET_SIZE, String.valueOf(4096 * 10));
    try {
        engine.configure(conf, bgTasks);
    } catch (IOException e) {
        fail("No IOException should be thrown");
    }
    try {
        for (int i = 0; i < 10; i++) {
            engine.writeDataPoint(MiscUtils.buildDataPoint("test", "ss", "value", Arrays.asList("te=2"), ts + (i * 4096 * 1000), 2.2));
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Engine is initialized, no IO Exception should be thrown:" + e.getMessage());
    }
    List<Series> queryDataPoints = engine.queryDataPoints("test", "ss", "value", ts, ts + (4096 * 100 * 1000) + 1, null);
    assertTrue(queryDataPoints.size() >= 1);
}
Also used : TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) Series(com.srotya.sidewinder.core.storage.Series) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) RejectException(com.srotya.sidewinder.core.storage.RejectException) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with StorageEngine

use of com.srotya.sidewinder.core.storage.StorageEngine in project sidewinder by srotya.

the class TestMemStorageEngine method testConfigure.

// @Test
// public void testWritePerformanceStress() throws Exception {
// final MemStorageEngine engine = new MemStorageEngine();
// engine.configure(new HashMap<>());
// long timeMillis = System.currentTimeMillis();
// int tcount = 64;
// ExecutorService es = Executors.newCachedThreadPool();
// int count = 10000000;
// final int modulator = 100;
// final AtomicInteger rejects = new AtomicInteger(0);
// for (int k = 0; k < tcount; k++) {
// final int j = k;
// es.submit(new Thread() {
// @Override
// public void run() {
// long ts = System.currentTimeMillis();
// for (int i = 0; i < count; i++) {
// if (isInterrupted()) {
// break;
// }
// try {
// DataPoint dp = MiscUtils.buildDataPoint(ts + i, i * 1.1);
// dp.setDbName("test"+j);
// dp.setMeasurementName("cpu");
// dp.setTags(Arrays.asList("test2", String.valueOf( + (i % modulator))));
// dp.setValueFieldName("value");
// engine.writeDataPoint(dp);
// } catch (IOException e) {
// rejects.incrementAndGet();
// }
// }
// }
// });
// }
// es.shutdown();
// es.awaitTermination(120, TimeUnit.SECONDS);
// int backOff = 30;
// while (!es.isTerminated()) {
// backOff = backOff * 2;
// Thread.sleep(backOff);
// }
// System.out.println("Write throughput direct " + tcount + "x" + count +
// ":"
// + (System.currentTimeMillis() - timeMillis) + "ms with " + rejects.get()
// + " rejects"
// + "\nWriting " + tcount + " each with " + (count/modulator) + " series");
// }
@Test
public void testConfigure() {
    StorageEngine engine = new MemStorageEngine();
    try {
        engine.writeDataPoint(MiscUtils.buildDataPoint("test", "ss", "value", Arrays.asList("te"), System.currentTimeMillis(), 2.2));
        fail("Engine not initialized, shouldn't be able to write a datapoint");
    } catch (Exception e) {
    }
    try {
        engine.configure(new HashMap<>(), bgTasks);
    } catch (IOException e) {
        fail("No IOException should be thrown");
    }
    try {
        engine.writeDataPoint(MiscUtils.buildDataPoint("test", "ss", "value", Arrays.asList("te=2"), System.currentTimeMillis(), 2.2));
    } catch (Exception e) {
        e.printStackTrace();
        fail("Engine is initialized, no IO Exception should be thrown:" + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) RejectException(com.srotya.sidewinder.core.storage.RejectException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

StorageEngine (com.srotya.sidewinder.core.storage.StorageEngine)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)11 LinkedHashMap (java.util.LinkedHashMap)11 File (java.io.File)10 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)9 RejectException (com.srotya.sidewinder.core.storage.RejectException)8 IOException (java.io.IOException)8 Series (com.srotya.sidewinder.core.storage.Series)6 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)6 Point (com.srotya.sidewinder.core.rpc.Point)5 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)5 Measurement (com.srotya.sidewinder.core.storage.Measurement)2 Gson (com.google.gson.Gson)1 SimpleTagFilter (com.srotya.sidewinder.core.filters.SimpleTagFilter)1 DBMetadata (com.srotya.sidewinder.core.storage.DBMetadata)1 ByzantineWriter (com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter)1 BackgrounThreadFactory (com.srotya.sidewinder.core.utils.BackgrounThreadFactory)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1