Package net.opentsdb.tree

Examples of net.opentsdb.tree.Tree


    assertNull(tree.getRule(3, 0));
  }
 
  @Test
  public void getRuleNoLevel() throws Exception {
    final Tree tree = buildTestTree();
    assertNull(tree.getRule(42, 0));
  }
View Full Code Here


    assertNull(tree.getRule(42, 0));
  }
 
  @Test
  public void getRuleNoOrder() throws Exception {
    final Tree tree = buildTestTree();
    assertNull(tree.getRule(3, 42));
  }
View Full Code Here

  }

  @Test
  public void createNewTree() throws Exception {
    setupStorage(true, true);
    final Tree tree = new Tree();
    tree.setName("New Tree");
    final int tree_id = tree.createNewTree(storage.getTSDB())
    .joinUninterruptibly();
    assertEquals(3, tree_id);
    assertEquals(5, storage.numRows());
    assertEquals(1, storage.numColumns(new byte[] { 0, 3 }));
  }
View Full Code Here

  @Test
  public void createNewFirstTree() throws Exception {
    setupStorage(true, true);
    storage.flushStorage();
    final Tree tree = new Tree();
    tree.setName("New Tree");
    final int tree_id = tree.createNewTree(storage.getTSDB())
    .joinUninterruptibly();
    assertEquals(1, tree_id);
    assertEquals(1, storage.numRows());
    assertEquals(1, storage.numColumns(new byte[] { 0, 1 }));
  }
View Full Code Here

  }
 
  @Test (expected = IllegalArgumentException.class)
  public void createNewTreeNoChanges() throws Exception {
    setupStorage(true, true);
    final Tree tree = new Tree();
    tree.createNewTree(storage.getTSDB()).joinUninterruptibly();
  }
View Full Code Here

 
  @Test (expected = IllegalArgumentException.class)
  public void createNewTreeOutOfIDs() throws Exception {
    setupStorage(true, true);

    final Tree max_tree = new Tree(65535);
    max_tree.setName("max");
    storage.addColumn(new byte[] { (byte) 0xFF, (byte) 0xFF },
        "tree".getBytes(MockBase.ASCII()), JSON.serializeToBytes(max_tree));
   
    final Tree tree = new Tree();
    tree.createNewTree(storage.getTSDB()).joinUninterruptibly();
  }
View Full Code Here

  }

  @Test
  public void fetchTree() throws Exception {
    setupStorage(true, true);
    final Tree tree = Tree.fetchTree(storage.getTSDB(), 1)
    .joinUninterruptibly();
    assertNotNull(tree);
    assertEquals("Test Tree", tree.getName());
    assertEquals(2, tree.getRules().size());
    assertTrue(tree.getEnabled());
  }
View Full Code Here

  /**
   * Returns a configured tree with rules and values for testing purposes
   * @return A tree to test with
   */
  public static Tree buildTestTree() {
    final Tree tree = new Tree();
    tree.setTreeId(1);
    tree.setCreated(1356998400L);
    tree.setDescription("My Description");
    tree.setName("Test Tree");
    tree.setNotes("Details");
    tree.setEnabled(true);
    buildTestRuleSet(tree);
   
    // reset the changed field via reflection
    Method reset;
    try {
View Full Code Here

        (byte[])branch_json.invoke(root));
   
    // tree 2
    key = new byte[] { 0, 2 };

    Tree tree2 = new Tree();
    tree2.setTreeId(2);
    tree2.setName("2nd Tree");
    tree2.setDescription("Other Tree");
    storage.addColumn(key, "tree".getBytes(MockBase.ASCII()),
        (byte[])TreetoStorageJson.invoke(tree2));
   
    rule = new TreeRule(2);
    rule.setField("host");
View Full Code Here

   * Setups objects in MockBase including two trees, rule sets, root branch,
   * child branch, leaves and some collisions and no matches. These are used for
   * most of the tests so they're all here.
   */
  private void setupStorage() throws Exception {        
    Tree tree = TestTree.buildTestTree();
    // store root
    TreeMap<Integer, String> root_path = new TreeMap<Integer, String>();
    Branch root = new Branch(tree.getTreeId());
    root.setDisplayName("ROOT");
    root_path.put(0, "ROOT");
    root.prependParentPath(root_path);
    storage.addColumn(root.compileBranchId(), Tree.TREE_FAMILY(),
        "branch".getBytes(MockBase.ASCII()),
        (byte[])branchToStorageJson.invoke(root));
   
    // store the first tree
    byte[] key = new byte[] { 0, 1 };
    storage.addColumn(key, Tree.TREE_FAMILY(), "tree".getBytes(MockBase.ASCII()),
        (byte[])TreetoStorageJson.invoke(TestTree.buildTestTree()));
   
    TreeRule rule = new TreeRule(1);
    rule.setField("host");
    rule.setDescription("Hostname rule");
    rule.setType(TreeRuleType.TAGK);
    rule.setDescription("Host Name");
    storage.addColumn(key, Tree.TREE_FAMILY(),
        "tree_rule:0:0".getBytes(MockBase.ASCII()),
        JSON.serializeToBytes(rule));

    rule = new TreeRule(1);
    rule.setField("");
    rule.setLevel(1);
    rule.setNotes("Metric rule");
    rule.setType(TreeRuleType.METRIC);
    storage.addColumn(key, Tree.TREE_FAMILY(),
        "tree_rule:1:0".getBytes(MockBase.ASCII()),
        JSON.serializeToBytes(rule));
   
    root = new Branch(1);
    root.setDisplayName("ROOT");
    root_path = new TreeMap<Integer, String>();
    root_path.put(0, "ROOT");
    root.prependParentPath(root_path);
    storage.addColumn(key, Tree.TREE_FAMILY(),
        "branch".getBytes(MockBase.ASCII()),
        (byte[])branchToStorageJson.invoke(root));
   
    // tree 2
    key = new byte[] { 0, 2 };

    Tree tree2 = new Tree();
    tree2.setTreeId(2);
    tree2.setName("2nd Tree");
    tree2.setDescription("Other Tree");
    storage.addColumn(key, Tree.TREE_FAMILY(), "tree".getBytes(MockBase.ASCII()),
        (byte[])TreetoStorageJson.invoke(tree2));
   
    rule = new TreeRule(2);
    rule.setField("host");
View Full Code Here

TOP

Related Classes of net.opentsdb.tree.Tree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.