Search in sources :

Example 6 with MockBase

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()));
}
Also used : Config(net.opentsdb.utils.Config) ArrayList(java.util.ArrayList) TSDB(net.opentsdb.core.TSDB) MockBase(net.opentsdb.storage.MockBase) Before(org.junit.Before)

Example 7 with MockBase

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));
}
Also used : Config(net.opentsdb.utils.Config) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Field(java.lang.reflect.Field) UIDMeta(net.opentsdb.meta.UIDMeta) TSDB(net.opentsdb.core.TSDB) MockBase(net.opentsdb.storage.MockBase) Before(org.junit.Before)

Example 8 with MockBase

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));
}
Also used : TreeRule(net.opentsdb.tree.TreeRule) ArrayList(java.util.ArrayList) MockBase(net.opentsdb.storage.MockBase)

Example 9 with MockBase

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");
        }
    });
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Deferred(com.stumbleupon.async.Deferred) MockBase(net.opentsdb.storage.MockBase)

Example 10 with MockBase

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);
}
Also used : Field(java.lang.reflect.Field) Config(net.opentsdb.utils.Config) HBaseClient(org.hbase.async.HBaseClient) MockBase(net.opentsdb.storage.MockBase)

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