Search in sources :

Example 26 with TSDB

use of net.opentsdb.core.TSDB in project opentsdb by OpenTSDB.

the class TestDumpSeries method before.

@Before
public void before() throws Exception {
    config = new Config(false);
    tsdb = new TSDB(client, config);
    storage = new MockBase(tsdb, client, true, true, true, true);
    storage.setFamily("t".getBytes(MockBase.ASCII()));
    buffer = new ByteArrayOutputStream();
    System.setOut(new PrintStream(buffer));
    // replace the "real" field objects with mocks
    Field met = tsdb.getClass().getDeclaredField("metrics");
    met.setAccessible(true);
    met.set(tsdb, metrics);
    Field tagk = tsdb.getClass().getDeclaredField("tag_names");
    tagk.setAccessible(true);
    tagk.set(tsdb, tag_names);
    Field tagv = tsdb.getClass().getDeclaredField("tag_values");
    tagv.setAccessible(true);
    tagv.set(tsdb, tag_values);
    // mock UniqueId
    when(metrics.getId("sys.cpu.user")).thenReturn(new byte[] { 0, 0, 1 });
    when(metrics.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("sys.cpu.user"));
    when(metrics.getId("sys.cpu.system")).thenThrow(new NoSuchUniqueName("sys.cpu.system", "metric"));
    when(metrics.getId("sys.cpu.nice")).thenReturn(new byte[] { 0, 0, 2 });
    when(metrics.getNameAsync(new byte[] { 0, 0, 2 })).thenReturn(Deferred.fromResult("sys.cpu.nice"));
    when(tag_names.getId("host")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_names.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("host"));
    when(tag_names.getOrCreateId("host")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_names.getId("dc")).thenThrow(new NoSuchUniqueName("dc", "metric"));
    when(tag_values.getId("web01")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_values.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("web01"));
    when(tag_values.getOrCreateId("web01")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_values.getId("web02")).thenReturn(new byte[] { 0, 0, 2 });
    when(tag_values.getNameAsync(new byte[] { 0, 0, 2 })).thenReturn(Deferred.fromResult("web02"));
    when(tag_values.getOrCreateId("web02")).thenReturn(new byte[] { 0, 0, 2 });
    when(tag_values.getId("web03")).thenThrow(new NoSuchUniqueName("web03", "metric"));
    when(metrics.width()).thenReturn((short) 3);
    when(tag_names.width()).thenReturn((short) 3);
    when(tag_values.width()).thenReturn((short) 3);
}
Also used : PrintStream(java.io.PrintStream) Field(java.lang.reflect.Field) Config(net.opentsdb.utils.Config) TSDB(net.opentsdb.core.TSDB) MockBase(net.opentsdb.storage.MockBase) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NoSuchUniqueName(net.opentsdb.uid.NoSuchUniqueName) Before(org.junit.Before)

Example 27 with TSDB

use of net.opentsdb.core.TSDB in project opentsdb by OpenTSDB.

the class TestUIDMeta method before.

@Before
public void before() throws Exception {
    final Config config = new Config(false);
    tsdb = new TSDB(client, config);
    storage = new MockBase(tsdb, client, true, true, true, true);
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, "metrics".getBytes(MockBase.ASCII()), "sys.cpu.0".getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 3 }, NAME_FAMILY, "metrics".getBytes(MockBase.ASCII()), "sys.cpu.2".getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, "metric_meta".getBytes(MockBase.ASCII()), ("{\"uid\":\"000001\",\"type\":\"METRIC\",\"name\":\"sys.cpu.0\"," + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":" + "1328140801,\"displayName\":\"System CPU\"}").getBytes(MockBase.ASCII()));
}
Also used : Config(net.opentsdb.utils.Config) TSDB(net.opentsdb.core.TSDB) MockBase(net.opentsdb.storage.MockBase) Before(org.junit.Before)

Example 28 with TSDB

use of net.opentsdb.core.TSDB in project opentsdb by OpenTSDB.

the class TestFsck method before.

@SuppressWarnings("unchecked")
@Before
public void before() throws Exception {
    config = new Config(false);
    tsdb = new TSDB(client, config);
    when(client.flush()).thenReturn(Deferred.fromResult(null));
    storage = new MockBase(tsdb, client, true, true, true, true);
    storage.setFamily("t".getBytes(MockBase.ASCII()));
    when(options.fix()).thenReturn(false);
    when(options.compact()).thenReturn(false);
    when(options.resolveDupes()).thenReturn(false);
    when(options.lastWriteWins()).thenReturn(false);
    when(options.deleteOrphans()).thenReturn(false);
    when(options.deleteUnknownColumns()).thenReturn(false);
    when(options.deleteBadValues()).thenReturn(false);
    when(options.deleteBadRows()).thenReturn(false);
    when(options.deleteBadCompacts()).thenReturn(false);
    when(options.threads()).thenReturn(1);
    // replace the "real" field objects with mocks
    Field met = tsdb.getClass().getDeclaredField("metrics");
    met.setAccessible(true);
    met.set(tsdb, metrics);
    Field tagk = tsdb.getClass().getDeclaredField("tag_names");
    tagk.setAccessible(true);
    tagk.set(tsdb, tag_names);
    Field tagv = tsdb.getClass().getDeclaredField("tag_values");
    tagv.setAccessible(true);
    tagv.set(tsdb, tag_values);
    // mock UniqueId
    when(metrics.getId("sys.cpu.user")).thenReturn(new byte[] { 0, 0, 1 });
    when(metrics.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("sys.cpu.user"));
    when(metrics.getId("sys.cpu.system")).thenThrow(new NoSuchUniqueName("sys.cpu.system", "metric"));
    when(metrics.getId("sys.cpu.nice")).thenReturn(new byte[] { 0, 0, 2 });
    when(metrics.getName(new byte[] { 0, 0, 2 })).thenReturn("sys.cpu.nice");
    when(tag_names.getId("host")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_names.getName(new byte[] { 0, 0, 1 })).thenReturn("host");
    when(tag_names.getOrCreateId("host")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_names.getId("dc")).thenThrow(new NoSuchUniqueName("dc", "metric"));
    when(tag_values.getId("web01")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_values.getName(new byte[] { 0, 0, 1 })).thenReturn("web01");
    when(tag_values.getOrCreateId("web01")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_values.getId("web02")).thenReturn(new byte[] { 0, 0, 2 });
    when(tag_values.getName(new byte[] { 0, 0, 2 })).thenReturn("web02");
    when(tag_values.getOrCreateId("web02")).thenReturn(new byte[] { 0, 0, 2 });
    when(tag_values.getId("web03")).thenThrow(new NoSuchUniqueName("web03", "metric"));
    PowerMockito.mockStatic(Tags.class);
    when(Tags.resolveIds((TSDB) any(), (ArrayList<byte[]>) any())).thenReturn(// don't care
    null);
    when(metrics.width()).thenReturn((short) 3);
    when(tag_names.width()).thenReturn((short) 3);
    when(tag_values.width()).thenReturn((short) 3);
}
Also used : Field(java.lang.reflect.Field) Config(net.opentsdb.utils.Config) TSDB(net.opentsdb.core.TSDB) MockBase(net.opentsdb.storage.MockBase) NoSuchUniqueName(net.opentsdb.uid.NoSuchUniqueName) Before(org.junit.Before)

Example 29 with TSDB

use of net.opentsdb.core.TSDB in project opentsdb by OpenTSDB.

the class TestFsckSalted method before.

@Before
public void before() throws Exception {
    PowerMockito.mockStatic(Const.class);
    PowerMockito.when(Const.SALT_BUCKETS()).thenReturn(2);
    PowerMockito.when(Const.SALT_WIDTH()).thenReturn(1);
    PowerMockito.when(Const.MAX_NUM_TAGS()).thenReturn((short) 8);
    GLOBAL_ROW = new byte[] { 0, 0, 0, 0, 0x52, (byte) 0xC3, 0x5A, (byte) 0x80 };
    ROW = MockBase.stringToBytes("0000000150E22700000001000001");
    ROW2 = MockBase.stringToBytes("0100000150E23510000001000001");
    ROW3 = MockBase.stringToBytes("0100000150E24320000001000001");
    BAD_KEY = new byte[] { 0x01, 0x00, 0x00, 0x01 };
    config = new Config(false);
    tsdb = new TSDB(client, config);
    when(client.flush()).thenReturn(Deferred.fromResult(null));
    storage = new MockBase(tsdb, client, true, true, true, true);
    storage.setFamily("t".getBytes(MockBase.ASCII()));
    when(options.fix()).thenReturn(false);
    when(options.compact()).thenReturn(false);
    when(options.resolveDupes()).thenReturn(false);
    when(options.lastWriteWins()).thenReturn(false);
    when(options.deleteOrphans()).thenReturn(false);
    when(options.deleteUnknownColumns()).thenReturn(false);
    when(options.deleteBadValues()).thenReturn(false);
    when(options.deleteBadRows()).thenReturn(false);
    when(options.deleteBadCompacts()).thenReturn(false);
    when(options.threads()).thenReturn(1);
    // replace the "real" field objects with mocks
    Field met = tsdb.getClass().getDeclaredField("metrics");
    met.setAccessible(true);
    met.set(tsdb, metrics);
    Field tagk = tsdb.getClass().getDeclaredField("tag_names");
    tagk.setAccessible(true);
    tagk.set(tsdb, tag_names);
    Field tagv = tsdb.getClass().getDeclaredField("tag_values");
    tagv.setAccessible(true);
    tagv.set(tsdb, tag_values);
    // mock UniqueId
    when(metrics.getId("sys.cpu.user")).thenReturn(new byte[] { 0, 0, 1 });
    when(metrics.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("sys.cpu.user"));
    when(metrics.getId("sys.cpu.system")).thenThrow(new NoSuchUniqueName("sys.cpu.system", "metric"));
    when(metrics.getId("sys.cpu.nice")).thenReturn(new byte[] { 0, 0, 2 });
    when(metrics.getName(new byte[] { 0, 0, 2 })).thenReturn("sys.cpu.nice");
    when(tag_names.getId("host")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_names.getName(new byte[] { 0, 0, 1 })).thenReturn("host");
    when(tag_names.getOrCreateId("host")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_names.getId("dc")).thenThrow(new NoSuchUniqueName("dc", "metric"));
    when(tag_values.getId("web01")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_values.getName(new byte[] { 0, 0, 1 })).thenReturn("web01");
    when(tag_values.getOrCreateId("web01")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_values.getId("web02")).thenReturn(new byte[] { 0, 0, 2 });
    when(tag_values.getName(new byte[] { 0, 0, 2 })).thenReturn("web02");
    when(tag_values.getOrCreateId("web02")).thenReturn(new byte[] { 0, 0, 2 });
    when(tag_values.getId("web03")).thenThrow(new NoSuchUniqueName("web03", "metric"));
    PowerMockito.mockStatic(Tags.class);
    when(Tags.resolveIds((TSDB) any(), (ArrayList<byte[]>) any())).thenReturn(// don't care
    null);
    when(metrics.width()).thenReturn((short) 3);
    when(tag_names.width()).thenReturn((short) 3);
    when(tag_values.width()).thenReturn((short) 3);
}
Also used : Field(java.lang.reflect.Field) Config(net.opentsdb.utils.Config) TSDB(net.opentsdb.core.TSDB) MockBase(net.opentsdb.storage.MockBase) NoSuchUniqueName(net.opentsdb.uid.NoSuchUniqueName) Before(org.junit.Before)

Example 30 with TSDB

use of net.opentsdb.core.TSDB in project opentsdb by OpenTSDB.

the class TestTextImporter method before.

@Before
public void before() throws Exception {
    config = new Config(false);
    tsdb = new TSDB(client, config);
    storage = new MockBase(tsdb, client, true, true, true, true);
    storage.setFamily("t".getBytes(MockBase.ASCII()));
    // replace the "real" field objects with mocks
    Field met = tsdb.getClass().getDeclaredField("metrics");
    met.setAccessible(true);
    met.set(tsdb, metrics);
    Field tagk = tsdb.getClass().getDeclaredField("tag_names");
    tagk.setAccessible(true);
    tagk.set(tsdb, tag_names);
    Field tagv = tsdb.getClass().getDeclaredField("tag_values");
    tagv.setAccessible(true);
    tagv.set(tsdb, tag_values);
    PowerMockito.spy(TextImporter.class);
    // we need to purge the hash map before each unit test since it's a static
    // field
    datapoints.set(null, new HashMap<String, WritableDataPoints>());
    // mock UniqueId
    when(metrics.getId("sys.cpu.user")).thenReturn(new byte[] { 0, 0, 1 });
    when(metrics.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("sys.cpu.user"));
    when(metrics.getId("sys.cpu.system")).thenThrow(new NoSuchUniqueName("sys.cpu.system", "metric"));
    when(metrics.getOrCreateId("sys.cpu.system")).thenThrow(new NoSuchUniqueName("sys.cpu.system", "metric"));
    when(metrics.getId("sys.cpu.nice")).thenReturn(new byte[] { 0, 0, 2 });
    when(metrics.getName(new byte[] { 0, 0, 2 })).thenReturn("sys.cpu.nice");
    when(tag_names.getId("host")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_names.getName(new byte[] { 0, 0, 1 })).thenReturn("host");
    when(tag_names.getOrCreateId("host")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_names.getId("fqdn")).thenThrow(new NoSuchUniqueName("dc", "tagk"));
    when(tag_names.getOrCreateId("fqdn")).thenThrow(new NoSuchUniqueName("dc", "tagk"));
    when(tag_values.getId("web01")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_values.getName(new byte[] { 0, 0, 1 })).thenReturn("web01");
    when(tag_values.getOrCreateId("web01")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_values.getId("web02")).thenReturn(new byte[] { 0, 0, 2 });
    when(tag_values.getName(new byte[] { 0, 0, 2 })).thenReturn("web02");
    when(tag_values.getOrCreateId("web02")).thenReturn(new byte[] { 0, 0, 2 });
    when(tag_values.getId("web03")).thenThrow(new NoSuchUniqueName("web03", "tagv"));
    when(tag_values.getOrCreateId("web03")).thenThrow(new NoSuchUniqueName("web03", "tagv"));
    when(metrics.width()).thenReturn((short) 3);
    when(tag_names.width()).thenReturn((short) 3);
    when(tag_values.width()).thenReturn((short) 3);
}
Also used : WritableDataPoints(net.opentsdb.core.WritableDataPoints) Field(java.lang.reflect.Field) Config(net.opentsdb.utils.Config) TSDB(net.opentsdb.core.TSDB) MockBase(net.opentsdb.storage.MockBase) Matchers.anyString(org.mockito.Matchers.anyString) NoSuchUniqueName(net.opentsdb.uid.NoSuchUniqueName) Before(org.junit.Before)

Aggregations

TSDB (net.opentsdb.core.TSDB)43 Config (net.opentsdb.utils.Config)41 Before (org.junit.Before)16 Test (org.junit.Test)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 MockBase (net.opentsdb.storage.MockBase)13 KeyValue (org.hbase.async.KeyValue)12 ArrayList (java.util.ArrayList)11 Matchers.anyString (org.mockito.Matchers.anyString)11 UniqueIdType (net.opentsdb.uid.UniqueId.UniqueIdType)8 Field (java.lang.reflect.Field)6 NoSuchUniqueName (net.opentsdb.uid.NoSuchUniqueName)5 IOException (java.io.IOException)4 UnitTestException (net.opentsdb.core.BaseTsdbTest.UnitTestException)4 Deferred (com.stumbleupon.async.Deferred)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 DataPoint (net.opentsdb.core.DataPoint)2 Query (net.opentsdb.core.Query)2 HBaseException (org.hbase.async.HBaseException)2