@Test public void storeNew() throws Exception { meta = new TSMeta(new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1}, 1357300800000L); meta.setDisplayName("New DN"); meta.storeNew(tsdb); assertEquals("New DN", meta.getDisplayName()); }
@Test public void syncToStorageOverwrite() throws Exception { meta = new TSMeta(new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1}, 1357300800000L); meta.setDisplayName("New DN"); meta.syncToStorage(tsdb, true).joinUninterruptibly(); assertEquals("New DN", meta.getDisplayName()); assertEquals(0, meta.getRetention()); }
@Test public void deserialize() throws Exception { String json = "{\"tsuid\":\"ABCD\",\"" + "description\":\"Description\",\"notes\":\"Notes\",\"created\":1328140800," + "\"custom\":null,\"units\":\"\",\"retention\":42,\"max\":1.0,\"min\":" + "\"NaN\",\"displayName\":\"Display\",\"dataType\":\"Data\",\"lastReceived" + "\":1328140801,\"unknownkey\":null}"; TSMeta tsmeta = JSON.parseToObject(json, TSMeta.class); assertNotNull(tsmeta); assertEquals("ABCD", tsmeta.getTSUID()); assertEquals("Notes", tsmeta.getNotes()); assertEquals(42, tsmeta.getRetention()); }
@Test public void parseFromColumn() throws Exception { final KeyValue column = mock(KeyValue.class); when(column.key()).thenReturn(new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1}); when(column.value()) .thenReturn( storage.getColumn( new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1}, NAME_FAMILY, "ts_meta".getBytes(MockBase.ASCII()))); final TSMeta meta = TSMeta.parseFromColumn(tsdb, column, false).joinUninterruptibly(); assertNotNull(meta); assertEquals("000001000001000001", meta.getTSUID()); assertNull(meta.getMetric()); }
@Test public void counterExistsInStorageNot() throws Exception { storage.flushRow(new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1}); assertFalse( TSMeta.counterExistsInStorage(tsdb, new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1}) .joinUninterruptibly()); }
@Test public void getTSMeta() throws Exception { meta = TSMeta.getTSMeta(tsdb, "000001000001000001").joinUninterruptibly(); assertNotNull(meta); assertEquals("000001000001000001", meta.getTSUID()); assertEquals("sys.cpu.0", meta.getMetric().getName()); assertEquals(2, meta.getTags().size()); assertEquals("host", meta.getTags().get(0).getName()); assertEquals("web01", meta.getTags().get(1).getName()); assertEquals(1, meta.getTotalDatapoints()); // no support for timestamps in mockbase yet // assertEquals(1328140801L, meta.getLastReceived()); }
@Test(expected = NoSuchUniqueId.class) public void incrementAndGetCounterNSU() throws Exception { final byte[] tsuid = {0, 0, 1, 0, 0, 1, 0, 0, 2}; class ErrBack implements Callback<Object, Exception> { @Override public Object call(Exception e) throws Exception { Throwable ex = e; while (ex.getClass().equals(DeferredGroupException.class)) { ex = ex.getCause(); } throw (Exception) ex; } } TSMeta.incrementAndGetCounter(tsdb, tsuid).addErrback(new ErrBack()).joinUninterruptibly(); }
@Test(expected = NoSuchUniqueId.class) public void getTSMetaNSUTagv() throws Throwable { storage.addColumn( new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 2}, NAME_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())); try { TSMeta.getTSMeta(tsdb, "000001000001000002").joinUninterruptibly(); } catch (DeferredGroupException e) { throw e.getCause(); } }
@Test(expected = NoSuchUniqueId.class) public void parseFromColumnWithUIDMetaNSU() throws Exception { class ErrBack implements Callback<Object, Exception> { @Override public Object call(Exception e) throws Exception { Throwable ex = e; while (ex.getClass().equals(DeferredGroupException.class)) { ex = ex.getCause(); } throw (Exception) ex; } } final KeyValue column = mock(KeyValue.class); when(column.key()).thenReturn(new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 2}); when(column.value()) .thenReturn( ("{\"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())); TSMeta.parseFromColumn(tsdb, column, true).addErrback(new ErrBack()).joinUninterruptibly(); }
@Test public void getTSMetaDoesNotExist() throws Exception { meta = TSMeta.getTSMeta(tsdb, "000002000001000001").joinUninterruptibly(); assertNull(meta); }
@Test public void createConstructor() { meta = new TSMeta(new byte[] {0, 0, 1, 0, 0, 2, 0, 0, 3}, 1357300800000L); assertEquals(1357300800000L / 1000, meta.getCreated()); }
@Test public void META_QUALIFIER() throws Exception { assertArrayEquals("ts_meta".getBytes(MockBase.ASCII()), TSMeta.META_QUALIFIER()); }
@Test public void COUNTER_QUALIFIER() throws Exception { assertArrayEquals("ts_ctr".getBytes(MockBase.ASCII()), TSMeta.COUNTER_QUALIFIER()); }
@Test public void incrementAndGetCounter() throws Exception { final byte[] tsuid = {0, 0, 1, 0, 0, 1, 0, 0, 1}; TSMeta.incrementAndGetCounter(tsdb, tsuid).joinUninterruptibly(); verify(client).bufferAtomicIncrement((AtomicIncrementRequest) any()); }
@Test public void delete() throws Exception { meta = TSMeta.getTSMeta(tsdb, "000001000001000001").joinUninterruptibly(); meta.delete(tsdb); }
@Test public void counterExistsInStorage() throws Exception { assertTrue( TSMeta.counterExistsInStorage(tsdb, new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1}) .joinUninterruptibly()); }
@Test(expected = IllegalArgumentException.class) public void deleteNull() throws Exception { meta = new TSMeta(); meta.delete(tsdb); }
@Test public void metaExistsInStorage() throws Exception { assertTrue(TSMeta.metaExistsInStorage(tsdb, "000001000001000001").joinUninterruptibly()); }
@Test(expected = IllegalArgumentException.class) public void storeNewEmpty() throws Exception { meta = new TSMeta(""); meta.storeNew(tsdb); }
@Test(expected = IllegalStateException.class) public void syncToStorageNoChanges() throws Exception { meta = new TSMeta("ABCD"); meta.syncToStorage(tsdb, true).joinUninterruptibly(); }
@Test(expected = IllegalArgumentException.class) public void syncToStorageDoesNotExist() throws Exception { storage.flushRow(new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1}); meta = new TSMeta(new byte[] {0, 0, 1, 0, 0, 1, 0, 0, 1}, 1357300800000L); meta.syncToStorage(tsdb, false).joinUninterruptibly(); }
@Test(expected = IllegalArgumentException.class) public void syncToStorageNullTSUID() throws Exception { meta = new TSMeta(); meta.syncToStorage(tsdb, true).joinUninterruptibly(); }