Search in sources :

Example 16 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method appendsAndCompactedAndPuts.

@Test
public void appendsAndCompactedAndPuts() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(1);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    final byte[] qual = { 0x00, 0x07 };
    final byte[] val = Bytes.fromLong(42L);
    final byte[] qual2 = { 0x00, 0x17 };
    final byte[] val2 = Bytes.fromLong(5L);
    final byte[] qual3 = { 0x00, 0x27 };
    final byte[] val3 = Bytes.fromLong(3L);
    final byte[] qual4 = { 0x00, 0x37 };
    final byte[] val4 = Bytes.fromLong(2L);
    final byte[] qual5 = { 0x00, 0x47 };
    final byte[] val5 = Bytes.fromLong(1L);
    final byte[] qual6 = { 0x00, 0x57 };
    final byte[] val6 = Bytes.fromLong(0L);
    kvs.add(makekv(AppendDataPoints.APPEND_COLUMN_QUALIFIER, MockBase.concatByteArrays(qual, val, qual2, val2)));
    kvs.add(makekv(MockBase.concatByteArrays(qual3, qual4), MockBase.concatByteArrays(val3, val4, ZERO)));
    kvs.add(makekv(qual5, val5));
    kvs.add(makekv(qual6, val6));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual, qual2, qual3, qual4, qual5, qual6), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val, val2, val3, val4, val5, val6, ZERO), kv.value());
    // We had nothing to do so...
    // ... verify there were no put.
    verify(tsdb, never()).put(anyBytes(), anyBytes(), anyBytes());
    // ... verify there were no delete.
    verify(tsdb, never()).delete(anyBytes(), any(byte[][].class));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method tripleCompacted.

@Test
public void tripleCompacted() throws Exception {
    // Here we have a row with #kvs > scanner.maxNumKeyValues and the result
    // that was compacted during a query. The result is a bunch of compacted
    // columns. We want to make sure that we can merge them nicely
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(5);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    final byte[] qual1 = { 0x00, 0x07 };
    final byte[] val1 = Bytes.fromLong(4L);
    final byte[] qual2 = { 0x00, 0x27 };
    final byte[] val2 = Bytes.fromLong(5L);
    final byte[] qual12 = MockBase.concatByteArrays(qual1, qual2);
    // 2nd compaction
    final byte[] qual3 = { 0x00, 0x37 };
    final byte[] val3 = Bytes.fromLong(6L);
    final byte[] qual4 = { 0x00, 0x47 };
    final byte[] val4 = Bytes.fromLong(7L);
    final byte[] qual34 = MockBase.concatByteArrays(qual3, qual4);
    // 3rd compaction
    final byte[] qual5 = { 0x00, 0x57 };
    final byte[] val5 = Bytes.fromLong(8L);
    final byte[] qual6 = { 0x00, 0x67 };
    final byte[] val6 = Bytes.fromLong(9L);
    final byte[] qual56 = MockBase.concatByteArrays(qual5, qual6);
    kvs.add(makekv(qual12, MockBase.concatByteArrays(val1, val2, ZERO)));
    kvs.add(makekv(qual34, MockBase.concatByteArrays(val3, val4, ZERO)));
    kvs.add(makekv(qual56, MockBase.concatByteArrays(val5, val6, ZERO)));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual12, qual34, qual56), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val1, val2, val3, val4, val5, val6, ZERO), kv.value());
    // We wrote only the combined column.
    verify(tsdb, times(1)).put(KEY, MockBase.concatByteArrays(qual1, qual2, qual3, qual4, qual5, qual6), MockBase.concatByteArrays(val1, val2, val3, val4, val5, val6, ZERO));
    // And we had to delete the 3 partially compacted columns.
    verify(tsdb, times(1)).delete(eq(KEY), eqAnyOrder(new byte[][] { qual12, qual34, qual56 }));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method doubleAppendsAndPuts.

@Test
public void doubleAppendsAndPuts() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(1);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    final byte[] qual = { 0x00, 0x07 };
    final byte[] val = Bytes.fromLong(42L);
    final byte[] qual2 = { 0x00, 0x17 };
    final byte[] val2 = Bytes.fromLong(5L);
    final byte[] qual3 = { 0x00, 0x27 };
    final byte[] val3 = Bytes.fromLong(3L);
    final byte[] qual4 = { 0x00, 0x37 };
    final byte[] val4 = Bytes.fromLong(2L);
    final byte[] qual5 = { 0x00, 0x47 };
    final byte[] val5 = Bytes.fromLong(1L);
    final byte[] qual6 = { 0x00, 0x57 };
    final byte[] val6 = Bytes.fromLong(0L);
    kvs.add(makekv(AppendDataPoints.APPEND_COLUMN_QUALIFIER, MockBase.concatByteArrays(qual, val, qual2, val2)));
    kvs.add(makekv(qual3, val3));
    kvs.add(makekv(qual4, val4));
    kvs.add(makekv(AppendDataPoints.APPEND_COLUMN_QUALIFIER, MockBase.concatByteArrays(qual5, val5, qual6, val6)));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual, qual2, qual3, qual4, qual5, qual6), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val, val2, val3, val4, val5, val6, ZERO), kv.value());
    // We had nothing to do so...
    // ... verify there were no put.
    verify(tsdb, never()).put(anyBytes(), anyBytes(), anyBytes());
    // ... verify there were no delete.
    verify(tsdb, never()).delete(anyBytes(), any(byte[][].class));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method secondCompactMS.

@Test
public void secondCompactMS() throws Exception {
    // In this test the row has already been compacted, and another data
    // point was written in the mean time.
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(2);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    // This is 2 values already compacted together.
    final byte[] qual1 = { (byte) 0xF0, 0x00, 0x00, 0x07 };
    final byte[] val1 = Bytes.fromLong(4L);
    final byte[] qual2 = { (byte) 0xF0, 0x00, 0x02, 0x07 };
    final byte[] val2 = Bytes.fromLong(5L);
    final byte[] qual12 = MockBase.concatByteArrays(qual1, qual2);
    kvs.add(makekv(qual12, MockBase.concatByteArrays(val1, val2, ZERO)));
    // This data point came late.  Note that its time delta falls in between
    // that of the two data points above.
    final byte[] qual3 = { (byte) 0xF0, 0x00, 0x01, 0x07 };
    final byte[] val3 = Bytes.fromLong(6L);
    kvs.add(makekv(qual3, val3));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual1, qual3, qual2), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val1, val3, val2, ZERO), kv.value());
    // We had one row to compact, so one put to do.
    verify(tsdb, times(1)).put(KEY, MockBase.concatByteArrays(qual1, qual3, qual2), MockBase.concatByteArrays(val1, val3, val2, ZERO));
    // And we had to delete the individual cell + pre-existing compacted cell.
    verify(tsdb, times(1)).delete(eq(KEY), eqAnyOrder(new byte[][] { qual12, qual3 }));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method oneCellRowBadLength.

@Test
public void oneCellRowBadLength() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(1);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    final byte[] qual = { 0x00, 0x03 };
    final byte[] cqual = { 0x00, 0x07 };
    byte[] val = Bytes.fromLong(42L);
    kvs.add(makekv(qual, val));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(cqual, kv.qualifier());
    assertArrayEquals(val, kv.value());
    // The old one needed the length fixed up, so verify that we wrote the new one
    verify(tsdb, times(1)).put(KEY, cqual, val);
    // ... and deleted the old one
    verify(tsdb, times(1)).delete(KEY, new byte[][] { qual });
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Annotation (net.opentsdb.meta.Annotation)77 ArrayList (java.util.ArrayList)68 Test (org.junit.Test)63 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)63 KeyValue (org.hbase.async.KeyValue)50 DataPoints (net.opentsdb.core.DataPoints)18 TSQuery (net.opentsdb.core.TSQuery)15 MockDataPoints (net.opentsdb.storage.MockDataPoints)13 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)10 Matchers.anyString (org.mockito.Matchers.anyString)10 Deferred (com.stumbleupon.async.Deferred)5 IOException (java.io.IOException)5 Callback (com.stumbleupon.async.Callback)4 HashMap (java.util.HashMap)4 List (java.util.List)4 DataPoint (net.opentsdb.core.DataPoint)4 NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)3 Map (java.util.Map)2 IncomingDataPoint (net.opentsdb.core.IncomingDataPoint)2 Query (net.opentsdb.core.Query)2