use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestLeaf 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);
final List<byte[]> families = new ArrayList<byte[]>();
families.add(Tree.TREE_FAMILY());
storage.addTable(TREE_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, "tagk".getBytes(MockBase.ASCII()), "host".getBytes(MockBase.ASCII()));
storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, "tagv".getBytes(MockBase.ASCII()), "web01".getBytes(MockBase.ASCII()));
storage.addColumn(TREE_TABLE, new byte[] { 0, 1 }, Tree.TREE_FAMILY(), new Leaf("0", "000001000001000001").columnQualifier(), ("{\"displayName\":\"0\",\"tsuid\":\"000001000001000001\"}").getBytes(MockBase.ASCII()));
}
use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestTreeBuilder 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);
final List<byte[]> families = new ArrayList<byte[]>();
families.add(Tree.TREE_FAMILY());
storage.addTable(TREE_TABLE, families);
treebuilder = new TreeBuilder(storage.getTSDB(), tree);
PowerMockito.spy(Tree.class);
PowerMockito.doReturn(Deferred.fromResult(tree)).when(Tree.class, "fetchTree", (TSDB) any(), anyInt());
// set private fields via reflection so the UTs can change things at will
Field tag_metric = TSMeta.class.getDeclaredField("metric");
tag_metric.setAccessible(true);
tag_metric.set(meta, metric);
tag_metric.setAccessible(false);
ArrayList<UIDMeta> tags = new ArrayList<UIDMeta>(4);
tags.add(tagk1);
tags.add(tagv1);
tags.add(tagk2);
tags.add(tagv2);
Field tags_field = TSMeta.class.getDeclaredField("tags");
tags_field.setAccessible(true);
tags_field.set(meta, tags);
tags_field.setAccessible(false);
// store root
final TreeMap<Integer, String> root_path = new TreeMap<Integer, String>();
final Branch root = new Branch(tree.getTreeId());
root.setDisplayName("ROOT");
root_path.put(0, "ROOT");
root.prependParentPath(root_path);
storage.addColumn(TREE_TABLE, root.compileBranchId(), Tree.TREE_FAMILY(), BRANCH, (byte[]) toStorageJson.invoke(root));
}
use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestTreeRule method setupStorage.
/**
* Mocks classes for testing the storage calls
*/
private void setupStorage() throws Exception {
storage = new MockBase(tsdb, client, true, true, true, true);
final List<byte[]> families = new ArrayList<byte[]>();
families.add(Tree.TREE_FAMILY());
storage.addTable(TREE_TABLE, families);
final TreeRule stored_rule = new TreeRule(1);
stored_rule.setLevel(2);
stored_rule.setOrder(1);
stored_rule.setType(TreeRuleType.METRIC_CUSTOM);
stored_rule.setField("host");
stored_rule.setCustomField("owner");
stored_rule.setDescription("Host owner");
stored_rule.setNotes("Owner of the host machine");
// pretend there's a tree definition in the storage row
storage.addColumn(TREE_TABLE, new byte[] { 0, 1 }, Tree.TREE_FAMILY(), "tree".getBytes(MockBase.ASCII()), new byte[] { 1 });
// add a rule to the row
storage.addColumn(TREE_TABLE, new byte[] { 0, 1 }, Tree.TREE_FAMILY(), "tree_rule:2:1".getBytes(MockBase.ASCII()), JSON.serializeToBytes(stored_rule));
}
use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestSearchRpc method setupLookup.
private void setupLookup(final boolean use_meta) {
storage = new MockBase(tsdb, client, true, true, true, true);
if (use_meta) {
TestTimeSeriesLookup.generateMeta(tsdb, storage);
} else {
TestTimeSeriesLookup.generateData(tsdb, storage);
}
when(metrics.getNameAsync(new byte[] { 0, 0, 4 })).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult("filtered");
}
});
when(tag_names.getNameAsync(new byte[] { 0, 0, 6 })).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult("6");
}
});
when(tag_names.getNameAsync(new byte[] { 0, 0, 8 })).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult("8");
}
});
when(tag_names.getNameAsync(new byte[] { 0, 0, 9 })).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult("9");
}
});
when(tag_values.getNameAsync(new byte[] { 0, 0, 7 })).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult("7");
}
});
when(tag_values.getNameAsync(new byte[] { 0, 0, 5 })).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult("5");
}
});
when(tag_values.getNameAsync(new byte[] { 0, 0, 10 })).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult("10");
}
});
}
use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestTags method setupStorage.
// PRIVATE helpers to setup unit tests
private void setupStorage() throws Exception {
config = new Config(false);
client = mock(HBaseClient.class);
tsdb = new TSDB(config);
storage = new MockBase(tsdb, client, true, true, true, true);
// replace the "real" field objects with mocks
Field cl = tsdb.getClass().getDeclaredField("client");
cl.setAccessible(true);
cl.set(tsdb, client);
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);
when(metrics.width()).thenReturn((short) 3);
when(tag_names.width()).thenReturn((short) 3);
when(tag_values.width()).thenReturn((short) 3);
}
Aggregations