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()));
}
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"));
}
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());
}
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);
}
Aggregations