Search in sources :

Example 21 with MockBase

use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.

the class TestUniqueIdRpc method setupUID.

/**
   * Sets up common mocks for UID tests
   * @throws Exception if something goes pear shaped
   */
private void setupUID() 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\"," + "\"displayName\":\"System CPU\",\"description\":\"Description\"," + "\"notes\":\"MyNotes\",\"created\":1328140801,\"custom\":null}").getBytes(MockBase.ASCII()));
}
Also used : Config(net.opentsdb.utils.Config) TSDB(net.opentsdb.core.TSDB) MockBase(net.opentsdb.storage.MockBase)

Example 22 with MockBase

use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.

the class TestUniqueIdRpc method setupTSUID.

/**
   * Sets up common mocks for TSUID tests
   * @throws Exception if something goes pear shaped
   */
private void setupTSUID() throws Exception {
    final Config config = new Config(false);
    tsdb = new TSDB(client, config);
    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);
    storage = new MockBase(tsdb, client, true, true, true, true);
    final List<byte[]> families = new ArrayList<byte[]>(1);
    families.add(TSMeta.FAMILY);
    storage.addTable(META_TABLE, families);
    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, 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()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 2 }, NAME_FAMILY, "metrics".getBytes(MockBase.ASCII()), "sys.cpu.2".getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 2 }, NAME_FAMILY, "metric_meta".getBytes(MockBase.ASCII()), ("{\"uid\":\"000002\",\"type\":\"METRIC\",\"name\":\"sys.cpu.2\"," + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":" + "1328140801,\"displayName\":\"System CPU\"}").getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, "tagk".getBytes(MockBase.ASCII()), "host".getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, "tagk_meta".getBytes(MockBase.ASCII()), ("{\"uid\":\"000001\",\"type\":\"TAGK\",\"name\":\"host\"," + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":" + "1328140801,\"displayName\":\"Host server name\"}").getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 2 }, NAME_FAMILY, "tagk".getBytes(MockBase.ASCII()), "datacenter".getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 2 }, NAME_FAMILY, "tagk_meta".getBytes(MockBase.ASCII()), ("{\"uid\":\"000002\",\"type\":\"TAGK\",\"name\":\"datacenter\"," + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":" + "1328140801,\"displayName\":\"Host server name\"}").getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, "tagv".getBytes(MockBase.ASCII()), "web01".getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, "tagv_meta".getBytes(MockBase.ASCII()), ("{\"uid\":\"000001\",\"type\":\"TAGV\",\"name\":\"web01\"," + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":" + "1328140801,\"displayName\":\"Web server 1\"}").getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 3 }, NAME_FAMILY, "tagv".getBytes(MockBase.ASCII()), "web02".getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 3 }, NAME_FAMILY, "tagv_meta".getBytes(MockBase.ASCII()), ("{\"uid\":\"000003\",\"type\":\"TAGV\",\"name\":\"web02\"," + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":" + "1328140801,\"displayName\":\"Web server 1\"}").getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 2 }, NAME_FAMILY, "tagv".getBytes(MockBase.ASCII()), "dc01".getBytes(MockBase.ASCII()));
    storage.addColumn(UID_TABLE, new byte[] { 0, 0, 2 }, NAME_FAMILY, "tagv_meta".getBytes(MockBase.ASCII()), ("{\"uid\":\"000002\",\"type\":\"TAGV\",\"name\":\"dc01\"," + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":" + "1328140801,\"displayName\":\"Web server 1\"}").getBytes(MockBase.ASCII()));
    storage.addColumn(META_TABLE, new byte[] { 0, 0, 1, 0, 0, 1, 0, 0, 1 }, TSMeta.FAMILY, "ts_meta".getBytes(MockBase.ASCII()), ("{\"tsuid\":\"000001000001000001\",\"displayName\":\"Display\"," + "\"description\":\"Description\",\"notes\":\"Notes\",\"created" + "\":1366671600,\"custom\":null,\"units\":\"\",\"dataType\":" + "\"Data\",\"retention\":42,\"max\":1.0,\"min\":\"NaN\"}").getBytes(MockBase.ASCII()));
    storage.addColumn(META_TABLE, new byte[] { 0, 0, 1, 0, 0, 1, 0, 0, 1 }, TSMeta.FAMILY, "ts_ctr".getBytes(MockBase.ASCII()), Bytes.fromLong(1L));
    storage.addColumn(META_TABLE, new byte[] { 0, 0, 2, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 0, 2 }, TSMeta.FAMILY, "ts_meta".getBytes(MockBase.ASCII()), ("{\"tsuid\":\"000002000001000001000002000002\",\"displayName\":\"Display\"," + "\"description\":\"Description\",\"notes\":\"Notes\",\"created" + "\":1366671600,\"custom\":null,\"units\":\"\",\"dataType\":" + "\"Data\",\"retention\":42,\"max\":1.0,\"min\":\"NaN\"}").getBytes(MockBase.ASCII()));
    storage.addColumn(META_TABLE, new byte[] { 0, 0, 2, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 0, 2 }, TSMeta.FAMILY, "ts_ctr".getBytes(MockBase.ASCII()), Bytes.fromLong(1L));
    storage.addColumn(META_TABLE, new byte[] { 0, 0, 2, 0, 0, 1, 0, 0, 3, 0, 0, 2, 0, 0, 2 }, TSMeta.FAMILY, "ts_meta".getBytes(MockBase.ASCII()), ("{\"tsuid\":\"000002000001000003000002000002\",\"displayName\":\"Display\"," + "\"description\":\"Description\",\"notes\":\"Notes\",\"created" + "\":1366671600,\"custom\":null,\"units\":\"\",\"dataType\":" + "\"Data\",\"retention\":42,\"max\":1.0,\"min\":\"NaN\"}").getBytes(MockBase.ASCII()));
    storage.addColumn(META_TABLE, new byte[] { 0, 0, 2, 0, 0, 1, 0, 0, 3, 0, 0, 2, 0, 0, 2 }, TSMeta.FAMILY, "ts_ctr".getBytes(MockBase.ASCII()), Bytes.fromLong(1L));
    when(metrics.getId("sys.cpu.0")).thenReturn(new byte[] { 0, 0, 1 });
    when(metrics.getIdAsync("sys.cpu.0")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 1 }));
    when(metrics.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("sys.cpu.0"));
    when(metrics.getId("sys.cpu.2")).thenReturn(new byte[] { 0, 0, 2 });
    when(metrics.getIdAsync("sys.cpu.2")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 2 }));
    when(metrics.getNameAsync(new byte[] { 0, 0, 2 })).thenReturn(Deferred.fromResult("sys.cpu.2"));
    when(tag_names.getId("host")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_names.getIdAsync("host")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 1 }));
    when(tag_names.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("host"));
    when(tag_values.getId("web01")).thenReturn(new byte[] { 0, 0, 1 });
    when(tag_values.getIdAsync("web01")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 1 }));
    when(tag_values.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("web01"));
    when(tag_values.getId("web02")).thenReturn(new byte[] { 0, 0, 3 });
    when(tag_values.getIdAsync("web02")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 3 }));
    when(tag_values.getNameAsync(new byte[] { 0, 0, 3 })).thenReturn(Deferred.fromResult("web02"));
    when(tag_names.getId("datacenter")).thenReturn(new byte[] { 0, 0, 2 });
    when(tag_names.getIdAsync("datacenter")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 2 }));
    when(tag_names.getNameAsync(new byte[] { 0, 0, 2 })).thenReturn(Deferred.fromResult("datacenter"));
    when(tag_values.getId("dc01")).thenReturn(new byte[] { 0, 0, 2 });
    when(tag_values.getIdAsync("dc01")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 2 }));
    when(tag_values.getNameAsync(new byte[] { 0, 0, 2 })).thenReturn(Deferred.fromResult("dc01"));
}
Also used : Field(java.lang.reflect.Field) Config(net.opentsdb.utils.Config) ArrayList(java.util.ArrayList) TSDB(net.opentsdb.core.TSDB) MockBase(net.opentsdb.storage.MockBase)

Example 23 with MockBase

use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.

the class TestUniqueId method setupStorage.

// ----------------- //
// Helper functions. //
// ----------------- //
private void setupStorage() throws Exception {
    final Config config = mock(Config.class);
    when(tsdb.getConfig()).thenReturn(config);
    when(tsdb.getClient()).thenReturn(client);
    storage = new MockBase(tsdb, client, true, true, true, true);
    final List<byte[]> families = new ArrayList<byte[]>();
    families.add(ID);
    families.add(NAME);
    storage.addTable(table, families);
    storage.addColumn(table, "sys.cpu.user".getBytes(), ID, METRIC_ARRAY, UID);
    storage.addColumn(table, UID, NAME, METRIC_ARRAY, "sys.cpu.user".getBytes());
    storage.addColumn(table, "host".getBytes(), ID, TAGK_ARRAY, UID);
    storage.addColumn(table, UID, NAME, TAGK_ARRAY, "host".getBytes());
    storage.addColumn(table, "web01".getBytes(), ID, TAGV_ARRAY, UID);
    storage.addColumn(table, UID, NAME, TAGV_ARRAY, "web01".getBytes());
}
Also used : Config(net.opentsdb.utils.Config) ArrayList(java.util.ArrayList) MockBase(net.opentsdb.storage.MockBase)

Example 24 with MockBase

use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.

the class TestQueryRpcLastDataPoint method beforeLocal.

@Before
public void beforeLocal() throws Exception {
    Whitebox.setInternalState(config, "enable_tsuid_incrementing", true);
    Whitebox.setInternalState(config, "enable_realtime_ts", true);
    rpc = new QueryRpc();
    storage = new MockBase(tsdb, client, true, true, true, true);
    TestTSUIDQuery.setupStorage(tsdb, storage);
}
Also used : MockBase(net.opentsdb.storage.MockBase) Before(org.junit.Before)

Aggregations

MockBase (net.opentsdb.storage.MockBase)24 Config (net.opentsdb.utils.Config)15 TSDB (net.opentsdb.core.TSDB)13 Before (org.junit.Before)13 ArrayList (java.util.ArrayList)9 Field (java.lang.reflect.Field)7 NoSuchUniqueName (net.opentsdb.uid.NoSuchUniqueName)4 TreeMap (java.util.TreeMap)3 HBaseClient (org.hbase.async.HBaseClient)2 Deferred (com.stumbleupon.async.Deferred)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Method (java.lang.reflect.Method)1 WritableDataPoints (net.opentsdb.core.WritableDataPoints)1 UIDMeta (net.opentsdb.meta.UIDMeta)1 Tree (net.opentsdb.tree.Tree)1 TreeRule (net.opentsdb.tree.TreeRule)1 Matchers.anyString (org.mockito.Matchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1