use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestUID method setupMockBase.
/**
* Write clean data to MockBase that can be overridden by individual unit tests
*/
private void setupMockBase() {
storage = new MockBase(tsdb, client, true, true, true, true);
storage.addColumn(UID_TABLE, new byte[] { 0 }, ID_FAMILY, METRICS, Bytes.fromLong(2L));
storage.addColumn(UID_TABLE, new byte[] { 0 }, ID_FAMILY, TAGK, Bytes.fromLong(2L));
storage.addColumn(UID_TABLE, new byte[] { 0 }, ID_FAMILY, TAGV, Bytes.fromLong(2L));
// forward mappings
storage.addColumn(UID_TABLE, "foo".getBytes(MockBase.ASCII()), ID_FAMILY, METRICS, new byte[] { 0, 0, 1 });
storage.addColumn(UID_TABLE, "host".getBytes(MockBase.ASCII()), ID_FAMILY, TAGK, new byte[] { 0, 0, 1 });
storage.addColumn(UID_TABLE, "web01".getBytes(MockBase.ASCII()), ID_FAMILY, TAGV, new byte[] { 0, 0, 1 });
storage.addColumn(UID_TABLE, "bar".getBytes(MockBase.ASCII()), ID_FAMILY, METRICS, new byte[] { 0, 0, 2 });
storage.addColumn(UID_TABLE, "dc".getBytes(MockBase.ASCII()), ID_FAMILY, TAGK, new byte[] { 0, 0, 2 });
storage.addColumn(UID_TABLE, "web02".getBytes(MockBase.ASCII()), ID_FAMILY, TAGV, new byte[] { 0, 0, 2 });
// reverse mappings
storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, METRICS, "foo".getBytes(MockBase.ASCII()));
storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, TAGK, "host".getBytes(MockBase.ASCII()));
storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, TAGV, "web01".getBytes(MockBase.ASCII()));
storage.addColumn(UID_TABLE, new byte[] { 0, 0, 2 }, NAME_FAMILY, METRICS, "bar".getBytes(MockBase.ASCII()));
storage.addColumn(UID_TABLE, new byte[] { 0, 0, 2 }, NAME_FAMILY, TAGK, "dc".getBytes(MockBase.ASCII()));
storage.addColumn(UID_TABLE, new byte[] { 0, 0, 2 }, NAME_FAMILY, TAGV, "web02".getBytes(MockBase.ASCII()));
}
use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestTextImporter method before.
@Before
public void before() throws Exception {
config = new Config(false);
tsdb = new TSDB(client, config);
storage = new MockBase(tsdb, client, true, true, true, true);
storage.setFamily("t".getBytes(MockBase.ASCII()));
// replace the "real" field objects with mocks
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);
PowerMockito.spy(TextImporter.class);
// we need to purge the hash map before each unit test since it's a static
// field
datapoints.set(null, new HashMap<String, WritableDataPoints>());
// mock UniqueId
when(metrics.getId("sys.cpu.user")).thenReturn(new byte[] { 0, 0, 1 });
when(metrics.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("sys.cpu.user"));
when(metrics.getId("sys.cpu.system")).thenThrow(new NoSuchUniqueName("sys.cpu.system", "metric"));
when(metrics.getOrCreateId("sys.cpu.system")).thenThrow(new NoSuchUniqueName("sys.cpu.system", "metric"));
when(metrics.getId("sys.cpu.nice")).thenReturn(new byte[] { 0, 0, 2 });
when(metrics.getName(new byte[] { 0, 0, 2 })).thenReturn("sys.cpu.nice");
when(tag_names.getId("host")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_names.getName(new byte[] { 0, 0, 1 })).thenReturn("host");
when(tag_names.getOrCreateId("host")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_names.getId("fqdn")).thenThrow(new NoSuchUniqueName("dc", "tagk"));
when(tag_names.getOrCreateId("fqdn")).thenThrow(new NoSuchUniqueName("dc", "tagk"));
when(tag_values.getId("web01")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_values.getName(new byte[] { 0, 0, 1 })).thenReturn("web01");
when(tag_values.getOrCreateId("web01")).thenReturn(new byte[] { 0, 0, 1 });
when(tag_values.getId("web02")).thenReturn(new byte[] { 0, 0, 2 });
when(tag_values.getName(new byte[] { 0, 0, 2 })).thenReturn("web02");
when(tag_values.getOrCreateId("web02")).thenReturn(new byte[] { 0, 0, 2 });
when(tag_values.getId("web03")).thenThrow(new NoSuchUniqueName("web03", "tagv"));
when(tag_values.getOrCreateId("web03")).thenThrow(new NoSuchUniqueName("web03", "tagv"));
when(metrics.width()).thenReturn((short) 3);
when(tag_names.width()).thenReturn((short) 3);
when(tag_values.width()).thenReturn((short) 3);
}
use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestTimeSeriesLookup method beforeLocal.
@Before
public void beforeLocal() {
storage = new MockBase(tsdb, client, true, true, true, true);
when(metrics.getIdAsync("no.values")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 11 }));
when(metrics.getIdAsync("filtered")).thenReturn(Deferred.fromResult(new byte[] { 0, 0, 4 }));
}
use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestTree method setupStorage.
/**
* Mocks classes for testing the storage calls
*/
private void setupStorage(final boolean default_get, final boolean default_put) throws Exception {
storage = new MockBase(tsdb, client, default_get, default_put, true, true);
final List<byte[]> families = new ArrayList<byte[]>(1);
families.add(Tree.TREE_FAMILY());
storage.addTable(TREE_TABLE, families);
byte[] key = new byte[] { 0, 1 };
// set pre-test values
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree".getBytes(MockBase.ASCII()), (byte[]) TreetoStorageJson.invoke(buildTestTree()));
TreeRule rule = new TreeRule(1);
rule.setField("host");
rule.setType(TreeRuleType.TAGK);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree_rule:0:0".getBytes(MockBase.ASCII()), JSON.serializeToBytes(rule));
rule = new TreeRule(1);
rule.setField("");
rule.setLevel(1);
rule.setType(TreeRuleType.METRIC);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree_rule:1:0".getBytes(MockBase.ASCII()), JSON.serializeToBytes(rule));
Branch root = new Branch(1);
root.setDisplayName("ROOT");
TreeMap<Integer, String> root_path = new TreeMap<Integer, String>();
root_path.put(0, "ROOT");
root.prependParentPath(root_path);
// TODO - static
Method branch_json = Branch.class.getDeclaredMethod("toStorageJson");
branch_json.setAccessible(true);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "branch".getBytes(MockBase.ASCII()), (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(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree".getBytes(MockBase.ASCII()), (byte[]) TreetoStorageJson.invoke(tree2));
rule = new TreeRule(2);
rule.setField("host");
rule.setType(TreeRuleType.TAGK);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree_rule:0:0".getBytes(MockBase.ASCII()), JSON.serializeToBytes(rule));
rule = new TreeRule(2);
rule.setField("");
rule.setLevel(1);
rule.setType(TreeRuleType.METRIC);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "tree_rule:1:0".getBytes(MockBase.ASCII()), JSON.serializeToBytes(rule));
root = new Branch(2);
root.setDisplayName("ROOT");
root_path = new TreeMap<Integer, String>();
root_path.put(0, "ROOT");
root.prependParentPath(root_path);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), "branch".getBytes(MockBase.ASCII()), (byte[]) branch_json.invoke(root));
// sprinkle in some collisions and no matches for fun
// collisions
key = new byte[] { 0, 1, 1 };
String tsuid = "010101";
byte[] qualifier = new byte[Tree.COLLISION_PREFIX().length + (tsuid.length() / 2)];
System.arraycopy(Tree.COLLISION_PREFIX(), 0, qualifier, 0, Tree.COLLISION_PREFIX().length);
byte[] tsuid_bytes = UniqueId.stringToUid(tsuid);
System.arraycopy(tsuid_bytes, 0, qualifier, Tree.COLLISION_PREFIX().length, tsuid_bytes.length);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), qualifier, "AAAAAA".getBytes(MockBase.ASCII()));
tsuid = "020202";
qualifier = new byte[Tree.COLLISION_PREFIX().length + (tsuid.length() / 2)];
System.arraycopy(Tree.COLLISION_PREFIX(), 0, qualifier, 0, Tree.COLLISION_PREFIX().length);
tsuid_bytes = UniqueId.stringToUid(tsuid);
System.arraycopy(tsuid_bytes, 0, qualifier, Tree.COLLISION_PREFIX().length, tsuid_bytes.length);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), qualifier, "BBBBBB".getBytes(MockBase.ASCII()));
// not matched
key = new byte[] { 0, 1, 2 };
tsuid = "010101";
qualifier = new byte[Tree.NOT_MATCHED_PREFIX().length + (tsuid.length() / 2)];
System.arraycopy(Tree.NOT_MATCHED_PREFIX(), 0, qualifier, 0, Tree.NOT_MATCHED_PREFIX().length);
tsuid_bytes = UniqueId.stringToUid(tsuid);
System.arraycopy(tsuid_bytes, 0, qualifier, Tree.NOT_MATCHED_PREFIX().length, tsuid_bytes.length);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), qualifier, "Failed rule 0:0".getBytes(MockBase.ASCII()));
tsuid = "020202";
qualifier = new byte[Tree.NOT_MATCHED_PREFIX().length + (tsuid.length() / 2)];
System.arraycopy(Tree.NOT_MATCHED_PREFIX(), 0, qualifier, 0, Tree.NOT_MATCHED_PREFIX().length);
tsuid_bytes = UniqueId.stringToUid(tsuid);
System.arraycopy(tsuid_bytes, 0, qualifier, Tree.NOT_MATCHED_PREFIX().length, tsuid_bytes.length);
storage.addColumn(TREE_TABLE, key, Tree.TREE_FAMILY(), qualifier, "Failed rule 1:1".getBytes(MockBase.ASCII()));
}
use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestAnnotationRpc 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);
// add a global
storage.addColumn(global_row_key, new byte[] { 1, 0, 0 }, ("{\"startTime\":1328140800,\"endTime\":1328140801,\"description\":" + "\"Description\",\"notes\":\"Notes\",\"custom\":{\"owner\":" + "\"ops\"}}").getBytes(MockBase.ASCII()), 1328140799972L);
storage.addColumn(global_row_key, new byte[] { 1, 0, 1 }, ("{\"startTime\":1328140801,\"endTime\":1328140803,\"description\":" + "\"Global 2\",\"notes\":\"Nothing\"}").getBytes(MockBase.ASCII()), 1328140799973L);
// add a local
storage.addColumn(tsuid_row_key, new byte[] { 1, 0x0A, 0x02 }, ("{\"tsuid\":\"000001000001000001\",\"startTime\":1388450562," + "\"endTime\":1419984000,\"description\":\"Hello!\",\"notes\":" + "\"My Notes\",\"custom\":{\"owner\":\"ops\"}}").getBytes(MockBase.ASCII()), 1388448000003L);
storage.addColumn(tsuid_row_key, new byte[] { 1, 0x0A, 0x03 }, ("{\"tsuid\":\"000001000001000001\",\"startTime\":1388450563," + "\"endTime\":1419984000,\"description\":\"Note2\",\"notes\":" + "\"Nothing\"}").getBytes(MockBase.ASCII()), 1388448000004L);
// add some data points too
storage.addColumn(tsuid_row_key, new byte[] { 0x50, 0x10 }, new byte[] { 1 }, 1388448000005L);
storage.addColumn(tsuid_row_key, new byte[] { 0x50, 0x18 }, new byte[] { 2 }, 1388448000006L);
}
Aggregations