@Test(expected = IllegalArgumentException.class) public void addPointMSTooLarge() throws Exception { // It's an artificial limit and more thought needs to be put into it setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 10000000000000L, 42, tags).joinUninterruptibly(); }
@Test(expected = IllegalArgumentException.class) public void addPointMSNegative() throws Exception { // Fri, 13 Dec 1901 20:45:52 GMT // may support in the future, but 1.0 didn't setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", -2147483648000L, 42, tags).joinUninterruptibly(); }
@Test public void addPointBothSameTimeSecondAndMs() throws Exception { // this can happen if a second and an ms data point are stored for the same // timestamp. setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 1356998400L, 42, tags).joinUninterruptibly(); tsdb.addPoint("sys.cpu.user", 1356998400000L, 42, tags).joinUninterruptibly(); final byte[] row = new byte[] {0, 0, 1, 0x50, (byte) 0xE2, 0x27, 0, 0, 0, 1, 0, 0, 1}; byte[] value = storage.getColumn(row, new byte[] {0, 0}); assertEquals(2, storage.numColumns(row)); assertNotNull(value); assertEquals(42, value[0]); value = storage.getColumn(row, new byte[] {(byte) 0xF0, 0, 0, 0}); assertNotNull(value); // should have 7 digits of precision assertEquals(42, value[0]); }
@SuppressWarnings("unchecked") @Test(expected = NoSuchUniqueName.class) public void addPointNoAutoMetric() throws Exception { setupAddPointStorage(); when(IncomingDataPoints.rowKeyTemplate((TSDB) any(), anyString(), (Map<String, String>) any())) .thenThrow(new NoSuchUniqueName("sys.cpu.user", "metric")); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 1356998400, 42, tags).joinUninterruptibly(); }
@Test public void addPointBothSameTimeIntAndFloatMs() throws Exception { // this is an odd situation that can occur if the user puts an int and then // a float (or vice-versa) with the same timestamp. What happens in the // aggregators when this occurs? setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 1356998400500L, 42, tags).joinUninterruptibly(); tsdb.addPoint("sys.cpu.user", 1356998400500L, 42.5F, tags).joinUninterruptibly(); final byte[] row = new byte[] {0, 0, 1, 0x50, (byte) 0xE2, 0x27, 0, 0, 0, 1, 0, 0, 1}; byte[] value = storage.getColumn(row, new byte[] {(byte) 0xF0, 0, 0x7D, 0}); assertEquals(2, storage.numColumns(row)); assertNotNull(value); assertEquals(42, value[0]); value = storage.getColumn(row, new byte[] {(byte) 0xF0, 0, 0x7D, 11}); assertNotNull(value); // should have 7 digits of precision assertEquals(42.5F, Float.intBitsToFloat(Bytes.getInt(value)), 0.0000001); }
@Test public void addPointLongEndOfRow() throws Exception { setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 1357001999, 42, tags).joinUninterruptibly(); final byte[] row = new byte[] {0, 0, 1, 0x50, (byte) 0xE2, 0x27, 0, 0, 0, 1, 0, 0, 1}; final byte[] value = storage.getColumn(row, new byte[] {(byte) 0xE0, (byte) 0xF0}); assertNotNull(value); assertEquals(42, value[0]); }
@Test public void addPointLong8BytesNegative() throws Exception { setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 1356998400, -4294967296L, tags).joinUninterruptibly(); final byte[] row = new byte[] {0, 0, 1, 0x50, (byte) 0xE2, 0x27, 0, 0, 0, 1, 0, 0, 1}; final byte[] value = storage.getColumn(row, new byte[] {0, 7}); assertNotNull(value); assertEquals(-4294967296L, Bytes.getLong(value)); }
@Test public void addPointFloatPrecision() throws Exception { setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 1356998400, 42.5123459999F, tags).joinUninterruptibly(); final byte[] row = new byte[] {0, 0, 1, 0x50, (byte) 0xE2, 0x27, 0, 0, 0, 1, 0, 0, 1}; final byte[] value = storage.getColumn(row, new byte[] {0, 11}); assertNotNull(value); // should have 7 digits of precision assertEquals(42.512345F, Float.intBitsToFloat(Bytes.getInt(value)), 0.0000001); }
@Test public void addPointSecondOne() throws Exception { // hey, it's valid *shrug* Thu, 01 Jan 1970 00:00:01 GMT setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 1, 42, tags).joinUninterruptibly(); final byte[] row = new byte[] {0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1}; final byte[] value = storage.getColumn(row, new byte[] {0, 16}); assertNotNull(value); assertEquals(42, value[0]); }
@Test public void addPointMS2106() throws Exception { // Sun, 07 Feb 2106 06:28:15.000 GMT setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 4294967295000L, 42, tags).joinUninterruptibly(); final byte[] row = new byte[] {0, 0, 1, (byte) 0xFF, (byte) 0xFF, (byte) 0xF9, 0x60, 0, 0, 1, 0, 0, 1}; final byte[] value = storage.getColumn(row, new byte[] {(byte) 0xF6, (byte) 0x77, 0x46, 0}); assertNotNull(value); assertEquals(42, value[0]); }
@Test public void addPointMS2286() throws Exception { // It's an artificial limit and more thought needs to be put into it setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 9999999999999L, 42, tags).joinUninterruptibly(); final byte[] row = new byte[] {0, 0, 1, (byte) 0x54, (byte) 0x0B, (byte) 0xD9, 0x10, 0, 0, 1, 0, 0, 1}; final byte[] value = storage.getColumn(row, new byte[] {(byte) 0xFA, (byte) 0xAE, 0x5F, (byte) 0xC0}); assertNotNull(value); assertEquals(42, value[0]); }
@Test public void addPointLongManyMs() throws Exception { setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); long timestamp = 1356998400500L; for (int i = 1; i <= 50; i++) { tsdb.addPoint("sys.cpu.user", timestamp++, i, tags).joinUninterruptibly(); } final byte[] row = new byte[] {0, 0, 1, 0x50, (byte) 0xE2, 0x27, 0, 0, 0, 1, 0, 0, 1}; final byte[] value = storage.getColumn(row, new byte[] {(byte) 0xF0, 0, 0x7D, 0}); assertNotNull(value); assertEquals(1, value[0]); assertEquals(50, storage.numColumns(row)); }
@Test public void addPointMS1970() throws Exception { // Since it's just over Integer.MAX_VALUE, OpenTSDB will treat this as // a millisecond timestamp since it doesn't fit in 4 bytes. // Base time is 4294800 which is Thu, 19 Feb 1970 17:00:00 GMT // offset = F0A36000 or 167296 ms setupAddPointStorage(); HashMap<String, String> tags = new HashMap<String, String>(1); tags.put("host", "web01"); tsdb.addPoint("sys.cpu.user", 4294967296L, 42, tags).joinUninterruptibly(); final byte[] row = new byte[] {0, 0, 1, 0, (byte) 0x41, (byte) 0x88, (byte) 0x90, 0, 0, 1, 0, 0, 1}; final byte[] value = storage.getColumn(row, new byte[] {(byte) 0xF0, (byte) 0xA3, 0x60, 0}); assertNotNull(value); assertEquals(42, value[0]); }