Search in sources :

Example 1 with TreeRule

use of net.opentsdb.tree.TreeRule in project opentsdb by OpenTSDB.

the class TestTreeRule method storeRuleInvalidMissingCustomFieldTagvCustom.

@Test(expected = IllegalArgumentException.class)
public void storeRuleInvalidMissingCustomFieldTagvCustom() throws Exception {
    setupStorage();
    final TreeRule rule = new TreeRule(1);
    rule.setLevel(1);
    rule.setOrder(0);
    rule.setType(TreeRuleType.TAGV_CUSTOM);
    rule.setNotes("Just some notes");
    rule.setField("foo");
    rule.syncToStorage(storage.getTSDB(), false).joinUninterruptibly();
}
Also used : TreeRule(net.opentsdb.tree.TreeRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with TreeRule

use of net.opentsdb.tree.TreeRule in project opentsdb by OpenTSDB.

the class TestTreeRule method storeRuleInvalidMissingFieldMetricCustom.

@Test(expected = IllegalArgumentException.class)
public void storeRuleInvalidMissingFieldMetricCustom() throws Exception {
    setupStorage();
    final TreeRule rule = new TreeRule(1);
    rule.setLevel(1);
    rule.setOrder(0);
    rule.setType(TreeRuleType.METRIC_CUSTOM);
    rule.setNotes("Just some notes");
    rule.syncToStorage(storage.getTSDB(), false).joinUninterruptibly();
}
Also used : TreeRule(net.opentsdb.tree.TreeRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with TreeRule

use of net.opentsdb.tree.TreeRule 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 4 with TreeRule

use of net.opentsdb.tree.TreeRule in project opentsdb by OpenTSDB.

the class TestTreeRule method storeRuleBadID65536.

@Test(expected = IllegalArgumentException.class)
public void storeRuleBadID65536() throws Exception {
    setupStorage();
    final TreeRule rule = new TreeRule(65536);
    rule.syncToStorage(storage.getTSDB(), false);
}
Also used : TreeRule(net.opentsdb.tree.TreeRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with TreeRule

use of net.opentsdb.tree.TreeRule in project opentsdb by OpenTSDB.

the class TestTreeRule method fetchRule.

@Test
public void fetchRule() throws Exception {
    setupStorage();
    final TreeRule rule = TreeRule.fetchRule(storage.getTSDB(), 1, 2, 1).joinUninterruptibly();
    assertNotNull(rule);
    assertEquals(1, rule.getTreeId());
    assertEquals(2, rule.getLevel());
    assertEquals(1, rule.getOrder());
    assertEquals("Host owner", rule.getDescription());
}
Also used : TreeRule(net.opentsdb.tree.TreeRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TreeRule (net.opentsdb.tree.TreeRule)22 Test (org.junit.Test)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 DeferredGroupException (com.stumbleupon.async.DeferredGroupException)2 IOException (java.io.IOException)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 Tree (net.opentsdb.tree.Tree)2 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 TSDB (net.opentsdb.core.TSDB)1 MockBase (net.opentsdb.storage.MockBase)1 Branch (net.opentsdb.tree.Branch)1 Leaf (net.opentsdb.tree.Leaf)1 TestTree (net.opentsdb.tree.TestTree)1 Config (net.opentsdb.utils.Config)1 Before (org.junit.Before)1