Example usage for org.apache.cassandra.db BufferDecoratedKey BufferDecoratedKey

List of usage examples for org.apache.cassandra.db BufferDecoratedKey BufferDecoratedKey

Introduction

In this page you can find the example usage for org.apache.cassandra.db BufferDecoratedKey BufferDecoratedKey.

Prototype

public BufferDecoratedKey(Token token, ByteBuffer key) 

Source Link

Usage

From source file:com.knewton.mapreduce.SSTableColumnRecordReaderTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    conf = new Configuration();
    attemptId = new TaskAttemptID();
    Path inputPath = new Path(TABLE_PATH_STR);
    inputSplit = new FileSplit(inputPath, 0, 1, null);
    Descriptor desc = new Descriptor(new File(TABLE_PATH_STR), "keyspace", "columnFamily", 1, Type.FINAL);

    doReturn(desc).when(ssTableColumnRecordReader).getDescriptor();

    doNothing().when(ssTableColumnRecordReader).copyTablesToLocal(any(FileSystem.class), any(FileSystem.class),
            any(Path.class), any(TaskAttemptContext.class));

    doReturn(ssTableReader).when(ssTableColumnRecordReader).openSSTableReader(any(IPartitioner.class),
            any(CFMetaData.class));

    when(ssTableReader.estimatedKeys()).thenReturn(2L);
    when(ssTableReader.getScanner()).thenReturn(tableScanner);

    when(tableScanner.hasNext()).thenReturn(true, true, false);

    key = new BufferDecoratedKey(new StringToken("a"), ByteBuffer.wrap("b".getBytes()));
    CellNameType simpleDenseCellType = new SimpleDenseCellNameType(BytesType.instance);
    CellName cellName = simpleDenseCellType.cellFromByteBuffer(ByteBuffer.wrap("n".getBytes()));
    ByteBuffer counterBB = CounterContext.instance().createGlobal(CounterId.fromInt(0),
            System.currentTimeMillis(), 123L);
    value = BufferCounterCell.create(cellName, counterBB, System.currentTimeMillis(), 0L, Flag.PRESERVE_SIZE);

    SSTableIdentityIterator row1 = getNewRow();
    SSTableIdentityIterator row2 = getNewRow();

    when(tableScanner.next()).thenReturn(row1, row2);
}

From source file:com.knewton.mapreduce.SSTableRowRecordReaderTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    conf = new Configuration();
    attemptId = new TaskAttemptID();
    Path inputPath = new Path(TABLE_PATH_STR);
    inputSplit = new FileSplit(inputPath, 0, 1, null);
    Descriptor desc = new Descriptor(new File(TABLE_PATH_STR), "keyspace", "columnFamily", 1, Type.FINAL);

    doReturn(desc).when(ssTableRowRecordReader).getDescriptor();

    doNothing().when(ssTableRowRecordReader).copyTablesToLocal(any(FileSystem.class), any(FileSystem.class),
            any(Path.class), any(TaskAttemptContext.class));

    doReturn(ssTableReader).when(ssTableRowRecordReader).openSSTableReader(any(IPartitioner.class),
            any(CFMetaData.class));

    when(ssTableReader.estimatedKeys()).thenReturn(1L);
    when(ssTableReader.getScanner()).thenReturn(tableScanner);

    when(tableScanner.hasNext()).thenReturn(true, false);

    key = new BufferDecoratedKey(new StringToken("a"), ByteBuffer.wrap("b".getBytes()));

    row = mock(SSTableIdentityIterator.class);
    when(row.getKey()).thenReturn(key);//from  ww  w . j ava  2 s .  co m

    when(tableScanner.next()).thenReturn(row);
}

From source file:com.mirantis.magnetodb.cassandra.db.index.MagnetoDBLocalSecondaryIndex.java

License:Apache License

public void deleteForCleanup(ByteBuffer rowKey, Cell cell, OpOrder.Group opGroup) {
    if (isQueryPropertiesField)
        throw new UnsupportedOperationException();

    if (!cell.isLive())
        return;//  w w  w . ja v  a 2s  .co  m

    DecoratedKey valueKey = new BufferDecoratedKey(indexCfs.partitioner.getToken(rowKey), rowKey);
    ;
    int localDeletionTime = (int) (System.currentTimeMillis() / 1000);
    ColumnFamily cfi = ArrayBackedSortedColumns.factory.create(indexCfs.metadata, false, 1);
    cfi.addTombstone(makeIndexColumnName(rowKey, cell), localDeletionTime, cell.timestamp());
    indexCfs.apply(valueKey, cfi, SecondaryIndexManager.nullUpdater, opGroup, null);
    if (logger.isDebugEnabled())
        logger.debug("removed index entry for cleaned-up value {}:{}", valueKey, cfi);
}

From source file:com.mirantis.magnetodb.cassandra.db.index.MagnetoDBLocalSecondaryIndex.java

License:Apache License

public void insert(ByteBuffer rowKey, Cell cell, OpOrder.Group opGroup) {
    if (isQueryPropertiesField)
        return;/*from   ww w. j  a  v a2  s .  c o  m*/

    DecoratedKey valueKey = new BufferDecoratedKey(indexCfs.partitioner.getToken(rowKey), rowKey);
    ColumnFamily cfi = ArrayBackedSortedColumns.factory.create(indexCfs.metadata, false, 1);
    CellName name = makeIndexColumnName(rowKey, cell);
    if (cell instanceof ExpiringCell) {
        ExpiringCell ec = (ExpiringCell) cell;
        cfi.addColumn(new BufferExpiringCell(name, ByteBufferUtil.EMPTY_BYTE_BUFFER, ec.timestamp(),
                ec.getTimeToLive(), ec.getLocalDeletionTime()));
    } else {
        cfi.addColumn(new BufferCell(name, ByteBufferUtil.EMPTY_BYTE_BUFFER, cell.timestamp()));
    }
    if (logger.isDebugEnabled())
        logger.debug("applying index row {} in {}",
                indexCfs.metadata.getKeyValidator().getString(valueKey.getKey()), cfi);

    indexCfs.apply(valueKey, cfi, SecondaryIndexManager.nullUpdater, opGroup, null);
}

From source file:com.stratio.cassandra.lucene.service.RowKeysTest.java

License:Apache License

@Test
public void testConstructorRowKeys() {
    RowKeys rowKeys = new RowKeys();

    DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey = new RowKey(decoratedKey, clusteringKey);

    rowKeys.add(rowKey);/*  ww  w.j ava 2s. c om*/

    assertEquals("rowsKeys.add 1, size must return 1", 1, rowKeys.size());

    DecoratedKey decoratedKey2 = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey2 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey2 = new RowKey(decoratedKey2, clusteringKey2);

    rowKeys.add(rowKey2);

    assertEquals("rowsKeys.add 2, size() must return 2", 2, rowKeys.size());
}

From source file:com.stratio.cassandra.lucene.service.RowKeysTest.java

License:Apache License

@Test
public void testListConstructor() {
    DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey = new RowKey(decoratedKey, clusteringKey);

    DecoratedKey decoratedKey2 = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey2 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey2 = new RowKey(decoratedKey2, clusteringKey2);

    List<RowKey> list = new ArrayList<>();

    list.add(rowKey);/*from ww w  .  j av a2 s  . c o  m*/
    list.add(rowKey2);
    RowKeys rowKeys = new RowKeys(list);
    assertEquals("rowsKeys.add 2, size() must return 2", 2, rowKeys.size());

}

From source file:com.stratio.cassandra.lucene.service.RowKeysTest.java

License:Apache License

@Test
public void testIterator() {
    DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey = new RowKey(decoratedKey, clusteringKey);

    DecoratedKey decoratedKey2 = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey2 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey2 = new RowKey(decoratedKey2, clusteringKey2);

    DecoratedKey decoratedKey3 = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey3 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey3 = new RowKey(decoratedKey3, clusteringKey3);

    DecoratedKey decoratedKey4 = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey4 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey4 = new RowKey(decoratedKey4, clusteringKey4);

    RowKeys rowKeys = new RowKeys();
    rowKeys.add(rowKey);/*w w  w.ja v a 2s  .c  o  m*/
    rowKeys.add(rowKey2);
    rowKeys.add(rowKey3);
    rowKeys.add(rowKey4);

    int num = 4;
    for (RowKey rowKeyAux : rowKeys) {
        assertFalse("iterator returns a item that is npot added",
                rowKeyAux != rowKey && rowKeyAux != rowKey2 && rowKeyAux != rowKey3 && rowKeyAux != rowKey4);
        num--;
    }
    assertEquals("iterator return more items than expected ", num, 0);

}

From source file:com.stratio.cassandra.lucene.service.RowKeysTest.java

License:Apache License

@Test
public void testToString() {

    DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey = new RowKey(decoratedKey, clusteringKey);

    DecoratedKey decoratedKey2 = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey2 = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey2 = new RowKey(decoratedKey2, clusteringKey2);

    List<RowKey> list = new ArrayList<>();

    list.add(rowKey);//from w  w  w.  ja v a2  s .c om
    list.add(rowKey2);
    RowKeys rowKeys = new RowKeys(list);
    assertEquals("iterator return more items than expected ",
            "RowKeys{rowKeys=[" + rowKey.toString() + ", " + rowKey2.toString() + "]}", rowKeys.toString());
}

From source file:com.stratio.cassandra.lucene.service.RowKeyTest.java

License:Apache License

@Test
public void tesRowKey() {
    DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey = new RowKey(decoratedKey, clusteringKey);

    assertEquals("RowKey.getPartitionKey must return the same passsed as parameter", rowKey.getPartitionKey(),
            decoratedKey);/*  ww  w.  j a v a2 s  .  c  om*/

    assertEquals("RowKey.getClusteringKey must return the same passsed as parameter", rowKey.getClusteringKey(),
            clusteringKey);
}

From source file:com.stratio.cassandra.lucene.service.RowKeyTest.java

License:Apache License

@Test
public void testToString() {
    DecoratedKey decoratedKey = new BufferDecoratedKey(new LongToken((long) 10),
            ByteBufferUtil.EMPTY_BYTE_BUFFER);
    CellName clusteringKey = CellNames.simpleSparse(new ColumnIdentifier("aaaa", false));
    RowKey rowKey = new RowKey(decoratedKey, clusteringKey);

    assertEquals("RowKey.toString must return",
            "RowKey{partitionKey=DecoratedKey(10, ), " + "clusteringKey=" + clusteringKey.toString() + "}",
            rowKey.toString());/*www .j a v a2s .  c o m*/
}