use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestHistogramDataPointRpc method before.
@Before
public void before() throws Exception {
uid_map = Maps.newHashMap();
PowerMockito.mockStatic(Threads.class);
timer = new FakeTaskTimer();
PowerMockito.when(Threads.newTimer(anyString())).thenReturn(timer);
PowerMockito.when(Threads.newTimer(anyInt(), anyString())).thenReturn(timer);
PowerMockito.whenNew(HashedWheelTimer.class).withNoArguments().thenReturn(timer);
PowerMockito.whenNew(HBaseClient.class).withAnyArguments().thenReturn(client);
config = new Config(false);
config.overrideConfig("tsd.storage.enable_compaction", "false");
config.overrideConfig("tsd.core.histograms.config", "{\"net.opentsdb.core.SimpleHistogramDecoder\": 42}");
tsdb = new TSDB(config);
config.setAutoMetric(true);
Whitebox.setInternalState(tsdb, "metrics", metrics);
Whitebox.setInternalState(tsdb, "tag_names", tag_names);
Whitebox.setInternalState(tsdb, "tag_values", tag_values);
setupMetricMaps();
setupTagkMaps();
setupTagvMaps();
mockUID(UniqueIdType.METRIC, HISTOGRAM_METRIC_STRING, HISTOGRAM_METRIC_BYTES);
// add metrics and tags to the UIDs list for other functions to share
uid_map.put(METRIC_STRING, METRIC_BYTES);
uid_map.put(METRIC_B_STRING, METRIC_B_BYTES);
uid_map.put(NSUN_METRIC, NSUI_METRIC);
uid_map.put(HISTOGRAM_METRIC_STRING, HISTOGRAM_METRIC_BYTES);
uid_map.put(TAGK_STRING, TAGK_BYTES);
uid_map.put(TAGK_B_STRING, TAGK_B_BYTES);
uid_map.put(NSUN_TAGK, NSUI_TAGK);
uid_map.put(TAGV_STRING, TAGV_BYTES);
uid_map.put(TAGV_B_STRING, TAGV_B_BYTES);
uid_map.put(NSUN_TAGV, NSUI_TAGV);
uid_map.putAll(UIDS);
when(metrics.width()).thenReturn((short) 3);
when(tag_names.width()).thenReturn((short) 3);
when(tag_values.width()).thenReturn((short) 3);
tags = new HashMap<String, String>(1);
tags.put(TAGK_STRING, TAGV_STRING);
manager = new HistogramCodecManager(tsdb);
Whitebox.setInternalState(tsdb, "histogram_manager", manager);
storage = new MockBase(tsdb, client, true, true, true, true);
test_histo = new SimpleHistogram(42);
test_histo.addBucket(0F, 1F, 42L);
test_histo.addBucket(1F, 5F, 24L);
test_histo.setOverflow(1L);
// counters
raw_histograms = Whitebox.getInternalState(PutDataPointRpc.class, "raw_histograms");
raw_histograms.set(0);
raw_histograms_stored = Whitebox.getInternalState(PutDataPointRpc.class, "raw_histograms_stored");
raw_histograms_stored.set(0);
}
use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestBranch method setupStorage.
/**
* Mocks classes for testing the storage calls
*/
private void setupStorage() throws Exception {
final HBaseClient client = mock(HBaseClient.class);
final Config config = new Config(false);
storage = new MockBase(new TSDB(client, config), client, true, true, true, true);
final List<byte[]> families = new ArrayList<byte[]>();
families.add(Tree.TREE_FAMILY());
storage.addTable(TREE_TABLE, families);
Branch branch = new Branch(1);
TreeMap<Integer, String> path = new TreeMap<Integer, String>();
path.put(0, "ROOT");
path.put(1, "sys");
path.put(2, "cpu");
branch.prependParentPath(path);
branch.setDisplayName("cpu");
storage.addColumn(TREE_TABLE, branch.compileBranchId(), Tree.TREE_FAMILY(), "branch".getBytes(MockBase.ASCII()), (byte[]) toStorageJson.invoke(branch));
Leaf leaf = new Leaf("user", "000001000001000001");
byte[] qualifier = leaf.columnQualifier();
storage.addColumn(TREE_TABLE, branch.compileBranchId(), Tree.TREE_FAMILY(), qualifier, (byte[]) LeaftoStorageJson.invoke(leaf));
leaf = new Leaf("nice", "000002000002000002");
qualifier = leaf.columnQualifier();
storage.addColumn(TREE_TABLE, branch.compileBranchId(), Tree.TREE_FAMILY(), qualifier, (byte[]) LeaftoStorageJson.invoke(leaf));
// child branch
branch = new Branch(1);
path.put(3, "mboard");
branch.prependParentPath(path);
branch.setDisplayName("mboard");
storage.addColumn(TREE_TABLE, branch.compileBranchId(), Tree.TREE_FAMILY(), "branch".getBytes(MockBase.ASCII()), (byte[]) toStorageJson.invoke(branch));
leaf = new Leaf("Asus", "000003000003000003");
qualifier = leaf.columnQualifier();
storage.addColumn(TREE_TABLE, branch.compileBranchId(), Tree.TREE_FAMILY(), qualifier, (byte[]) LeaftoStorageJson.invoke(leaf));
}
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 TestTSMeta method before.
@Before
public void before() throws Exception {
config = mock(Config.class);
when(config.getString("tsd.storage.hbase.data_table")).thenReturn("tsdb");
when(config.getString("tsd.storage.hbase.uid_table")).thenReturn("tsdb-uid");
when(config.getString("tsd.storage.hbase.meta_table")).thenReturn("tsdb-meta");
when(config.getString("tsd.storage.hbase.tree_table")).thenReturn("tsdb-tree");
when(config.enable_tsuid_incrementing()).thenReturn(true);
when(config.enable_realtime_ts()).thenReturn(true);
tsdb = new TSDB(client, config);
storage = new MockBase(tsdb, client, true, true, true, true);
final List<byte[]> families = new ArrayList<byte[]>();
families.add(TSMeta.FAMILY);
storage.addTable(META_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, "metric_meta".getBytes(MockBase.ASCII()), ("{\"uid\":\"000001\",\"type\":\"METRIC\",\"name\":\"sys.cpu.0\"," + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":" + "1328140801,\"displayName\":\"System CPU\"}").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, "tagk_meta".getBytes(MockBase.ASCII()), ("{\"uid\":\"000001\",\"type\":\"TAGK\",\"name\":\"host\"," + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":" + "1328140801,\"displayName\":\"Host server name\"}").getBytes(MockBase.ASCII()));
storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, "tagv".getBytes(MockBase.ASCII()), "web01".getBytes(MockBase.ASCII()));
storage.addColumn(UID_TABLE, new byte[] { 0, 0, 1 }, NAME_FAMILY, "tagv_meta".getBytes(MockBase.ASCII()), ("{\"uid\":\"000001\",\"type\":\"TAGV\",\"name\":\"web01\"," + "\"description\":\"Description\",\"notes\":\"MyNotes\",\"created\":" + "1328140801,\"displayName\":\"Web server 1\"}").getBytes(MockBase.ASCII()));
storage.addColumn(META_TABLE, TSUID, NAME_FAMILY, "ts_meta".getBytes(MockBase.ASCII()), ("{\"tsuid\":\"000001000001000001\",\"" + "description\":\"Description\",\"notes\":\"Notes\",\"created\":1328140800," + "\"custom\":null,\"units\":\"\",\"retention\":42,\"max\":1.0,\"min\":" + "\"NaN\",\"displayName\":\"Display\",\"dataType\":\"Data\"}").getBytes(MockBase.ASCII()));
storage.addColumn(META_TABLE, TSUID, TSMeta.FAMILY, "ts_ctr".getBytes(MockBase.ASCII()), Bytes.fromLong(1L));
storage.addColumn(META_TABLE, new byte[] { 0, 0, 1, 0, 0, 1, 0, 0, 2 }, TSMeta.FAMILY, "ts_meta".getBytes(MockBase.ASCII()), ("{\"tsuid\":\"000001000001000002\",\"" + "description\":\"Description\",\"notes\":\"Notes\",\"created\":1328140800," + "\"custom\":null,\"units\":\"\",\"retention\":42,\"max\":1.0,\"min\":" + "\"NaN\",\"displayName\":\"Display\",\"dataType\":\"Data\"}").getBytes(MockBase.ASCII()));
}
use of net.opentsdb.storage.MockBase in project opentsdb by OpenTSDB.
the class TestAnnotation method setupStorage.
/**
* Sets up storage with or without salting and writes a few bits of data
* @param salted Whether or not to use salting
*/
private void setupStorage(final boolean salted) {
if (salted) {
PowerMockito.mockStatic(Const.class);
PowerMockito.when(Const.SALT_WIDTH()).thenReturn(1);
PowerMockito.when(Const.SALT_BUCKETS()).thenReturn(2);
}
global_row_key = new byte[Const.SALT_WIDTH() + TSDB.metrics_width() + Const.TIMESTAMP_BYTES];
System.arraycopy(Bytes.fromInt(1328140800), 0, global_row_key, Const.SALT_WIDTH() + TSDB.metrics_width(), Const.TIMESTAMP_BYTES);
global_row_key_2015_midnight = new byte[Const.SALT_WIDTH() + TSDB.metrics_width() + Const.TIMESTAMP_BYTES];
System.arraycopy(Bytes.fromInt(1425715200), 0, global_row_key_2015_midnight, Const.SALT_WIDTH() + TSDB.metrics_width(), Const.TIMESTAMP_BYTES);
tsuid_row_key = getRowKeyTemplate();
System.arraycopy(Bytes.fromInt(1388448000), 0, tsuid_row_key, Const.SALT_WIDTH() + TSDB.metrics_width(), Const.TIMESTAMP_BYTES);
RowKey.prefixKeyWithSalt(tsuid_row_key);
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