Search in sources :

Example 26 with Annotation

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

the class TestCompactionQueue method secondsOutOfOrder.

@Test
public void secondsOutOfOrder() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(3);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    final byte[] qual1 = { 0x02, 0x07 };
    final byte[] val1 = Bytes.fromLong(4L);
    kvs.add(makekv(qual1, val1));
    final byte[] qual2 = { 0x00, 0x07 };
    final byte[] val2 = Bytes.fromLong(5L);
    kvs.add(makekv(qual2, val2));
    final byte[] qual3 = { 0x01, 0x07 };
    final byte[] val3 = Bytes.fromLong(6L);
    kvs.add(makekv(qual3, val3));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual2, qual3, qual1), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val2, val3, val1, ZERO), kv.value());
    // We compacted all columns to one, so one put to do.
    verify(tsdb, times(1)).put(KEY, MockBase.concatByteArrays(qual2, qual3, qual1), MockBase.concatByteArrays(val2, val3, val1, ZERO));
    // And we had to delete individual cells.
    verify(tsdb, times(1)).delete(eq(KEY), eqAnyOrder(new byte[][] { qual1, qual2, 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 27 with Annotation

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

the class TestCompactionQueue method oneCellRowWAnnotation.

@Test
public void oneCellRowWAnnotation() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(1);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(1);
    kvs.add(makekv(note_qual, note));
    final byte[] qual = { 0x00, 0x07 };
    final byte[] val = Bytes.fromLong(42L);
    kvs.add(makekv(qual, val));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(qual, kv.qualifier());
    assertArrayEquals(val, kv.value());
    assertEquals(1, annotations.size());
    // 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 28 with Annotation

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

the class TestCompactionQueue method twoCellRowWAnnotation.

@Test
public void twoCellRowWAnnotation() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(2);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(1);
    kvs.add(makekv(note_qual, note));
    final byte[] qual1 = { 0x00, 0x07 };
    final byte[] val1 = Bytes.fromLong(4L);
    kvs.add(makekv(qual1, val1));
    final byte[] qual2 = { 0x00, 0x17 };
    final byte[] val2 = Bytes.fromLong(5L);
    kvs.add(makekv(qual2, val2));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual1, qual2), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val1, val2, ZERO), kv.value());
    assertEquals(1, annotations.size());
    // We had one row to compact, so one put to do.
    verify(tsdb, times(1)).put(KEY, MockBase.concatByteArrays(qual1, qual2), MockBase.concatByteArrays(val1, val2, ZERO));
    // And we had to delete individual cells.
    verify(tsdb, times(1)).delete(eq(KEY), eqAnyOrder(new byte[][] { qual1, qual2 }));
}
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 29 with Annotation

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

the class TestCompactionQueue method appendsAndEarlierPuts.

@Test
public void appendsAndEarlierPuts() 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);
    kvs.add(makekv(qual, val));
    kvs.add(makekv(qual2, val2));
    kvs.add(makekv(AppendDataPoints.APPEND_COLUMN_QUALIFIER, MockBase.concatByteArrays(qual3, val3, qual4, val4)));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual, qual2, qual3, qual4), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val, val2, val3, val4, 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 30 with Annotation

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

the class TestCompactionQueue method doubleFailedCompactNoop.

@Test
public void doubleFailedCompactNoop() throws Exception {
    // In this test the row has already been compacted once, but we didn't
    // clean up the individual data points.  Then another data point was
    // written, another compaction ran, but once again didn't delete the
    // individual data points.  So the rows contains 2 compacted cells and
    // several individual cells.
    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);
    // Data points 1 + 2 compacted.
    final byte[] qual12 = MockBase.concatByteArrays(qual1, qual2);
    // This data point came late.
    final byte[] qual3 = { 0x00, 0x17 };
    final byte[] val3 = Bytes.fromLong(6L);
    // Data points 1 + 3 + 2 compacted.
    final byte[] qual132 = MockBase.concatByteArrays(qual1, qual3, qual2);
    kvs.add(makekv(qual1, val1));
    kvs.add(makekv(qual132, MockBase.concatByteArrays(val1, val3, val2, ZERO)));
    kvs.add(makekv(qual12, MockBase.concatByteArrays(val1, val2, ZERO)));
    kvs.add(makekv(qual3, val3));
    kvs.add(makekv(qual2, val2));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(qual132, kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val1, val3, val2, ZERO), kv.value());
    // We didn't have anything to write, the last cell is already the correct
    // compacted version of the row.
    verify(tsdb, never()).put(anyBytes(), anyBytes(), anyBytes());
    // And we had to delete the 3 individual cells + the first pre-existing
    // compacted cell.
    verify(tsdb, times(1)).delete(eq(KEY), eqAnyOrder(new byte[][] { qual1, qual12, qual3, qual2 }));
}
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