Exemplo n.º 1
0
 @Test
 public void containsKeyReturnsFalseOnNonexistentKey() throws Exception {
   TransactionHandle txn = manager.beginTransaction();
   ByteBuffer key1 = KeyColumnValueStoreUtil.longToByteBuffer(1);
   assertFalse(store.containsKey(key1.duplicate(), txn));
   txn.commit();
 }
Exemplo n.º 2
0
  @Test
  public void getSliceRespectsAllBoundsInclusionArguments() throws Exception {
    // Test case where endColumn=startColumn+1
    ByteBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0);
    ByteBuffer columnBeforeStart = KeyColumnValueStoreUtil.longToByteBuffer(776);
    ByteBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(777);
    ByteBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(778);
    ByteBuffer columnAfterEnd = KeyColumnValueStoreUtil.longToByteBuffer(779);

    // First insert four test Entries
    TransactionHandle txn = manager.beginTransaction();
    List<Entry> entries =
        Arrays.asList(
            new Entry(columnBeforeStart, columnBeforeStart),
            new Entry(columnStart, columnStart),
            new Entry(columnEnd, columnEnd),
            new Entry(columnAfterEnd, columnAfterEnd));
    store.mutate(key, entries, null, txn);
    txn.commit();

    // getSlice() with only start inclusive
    txn = manager.beginTransaction();
    List<Entry> result = store.getSlice(key, columnStart, columnEnd, txn);
    assertEquals(1, result.size());
    assertEquals(777, result.get(0).getColumn().getLong());
    txn.commit();
  }
Exemplo n.º 3
0
 @Test
 public void getNonExistentKeyReturnsNull() throws Exception {
   TransactionHandle txn = manager.beginTransaction();
   assertEquals(null, KeyColumnValueStoreUtil.get(store, txn, 0, "col0"));
   assertEquals(null, KeyColumnValueStoreUtil.get(store, txn, 0, "col1"));
   txn.commit();
 }
Exemplo n.º 4
0
  @Test
  public void containsKeyColumnReturnsTrueOnExtantInput() throws Exception {
    TransactionHandle txn = manager.beginTransaction();
    KeyColumnValueStoreUtil.insert(store, txn, 1, "c", "v");
    txn.commit();

    txn = manager.beginTransaction();
    ByteBuffer key1 = KeyColumnValueStoreUtil.longToByteBuffer(1);
    ByteBuffer c = KeyColumnValueStoreUtil.stringToByteBuffer("c");
    assertTrue(store.containsKeyColumn(key1.duplicate(), c.duplicate(), txn));
    txn.commit();
  }
Exemplo n.º 5
0
  @Test
  public void getSliceRespectsColumnLimit() throws Exception {
    TransactionHandle txn = manager.beginTransaction();
    ByteBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0);

    final int cols = 1024;

    List<Entry> entries = new LinkedList<Entry>();
    for (int i = 0; i < cols; i++) {
      ByteBuffer col = KeyColumnValueStoreUtil.longToByteBuffer(i);
      entries.add(new Entry(col, col));
    }
    store.mutate(key, entries, null, txn);
    txn.commit();

    txn = manager.beginTransaction();
    ByteBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(0);
    ByteBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(cols);
    /*
     * When limit is greater than or equal to the matching column count,
     * all matching columns must be returned.
     */
    List<Entry> result = store.getSlice(key, columnStart, columnEnd, cols, txn);
    assertEquals(cols, result.size());
    assertEquals(entries, result);
    result = store.getSlice(key, columnStart, columnEnd, cols + 10, txn);
    assertEquals(cols, result.size());
    assertEquals(entries, result);

    /*
     * When limit is less the matching column count, the columns up to the
     * limit (ordered bytewise) must be returned.
     */
    result = store.getSlice(key, columnStart, columnEnd, cols - 1, txn);
    assertEquals(cols - 1, result.size());
    entries.remove(entries.size() - 1);
    assertEquals(entries, result);
    result = store.getSlice(key, columnStart, columnEnd, 1, txn);
    assertEquals(1, result.size());
    List<Entry> firstEntrySingleton = Arrays.asList(entries.get(0));
    assertEquals(firstEntrySingleton, result);
    txn.commit();
  }
Exemplo n.º 6
0
  @Test
  public void insertingGettingAndDeletingSimpleDataWorks() throws Exception {
    TransactionHandle txn = manager.beginTransaction();
    KeyColumnValueStoreUtil.insert(store, txn, 0, "col0", "val0");
    KeyColumnValueStoreUtil.insert(store, txn, 0, "col1", "val1");
    txn.commit();

    txn = manager.beginTransaction();
    assertEquals("val0", KeyColumnValueStoreUtil.get(store, txn, 0, "col0"));
    assertEquals("val1", KeyColumnValueStoreUtil.get(store, txn, 0, "col1"));
    KeyColumnValueStoreUtil.delete(store, txn, 0, "col0");
    KeyColumnValueStoreUtil.delete(store, txn, 0, "col1");
    txn.commit();

    txn = manager.beginTransaction();
    assertEquals(null, KeyColumnValueStoreUtil.get(store, txn, 0, "col0"));
    assertEquals(null, KeyColumnValueStoreUtil.get(store, txn, 0, "col1"));
    txn.commit();
  }
Exemplo n.º 7
0
 public void close() {
   if (tx != null) tx.commit();
   store.close();
   manager.close();
 }