Java Code Examples for org.apache.cassandra.utils.FBUtilities#singleton()

The following examples show how to use org.apache.cassandra.utils.FBUtilities#singleton() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadMessageTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetColumn()
{
    Keyspace keyspace = Keyspace.open("Keyspace1");
    CellNameType type = keyspace.getColumnFamilyStore("Standard1").getComparator();
    Mutation rm;
    DecoratedKey dk = Util.dk("key1");

    // add data
    rm = new Mutation("Keyspace1", dk.getKey());
    rm.add("Standard1", Util.cellname("Column1"), ByteBufferUtil.bytes("abcd"), 0);
    rm.apply();

    ReadCommand command = new SliceByNamesReadCommand("Keyspace1", dk.getKey(), "Standard1", System.currentTimeMillis(), new NamesQueryFilter(FBUtilities.singleton(Util.cellname("Column1"), type)));
    Row row = command.getRow(keyspace);
    Cell col = row.cf.getColumn(Util.cellname("Column1"));
    assertEquals(col.value(), ByteBuffer.wrap("abcd".getBytes()));
}
 
Example 2
Source File: CommitLogTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testTruncateWithoutSnapshotNonDurable()  throws ExecutionException, InterruptedException
{
    CommitLog.instance.resetUnsafe();
    boolean prevAutoSnapshot = DatabaseDescriptor.isAutoSnapshot();
    DatabaseDescriptor.setAutoSnapshot(false);
    Keyspace notDurableKs = Keyspace.open("NoCommitlogSpace");
    Assert.assertFalse(notDurableKs.metadata.durableWrites);
    ColumnFamilyStore cfs = notDurableKs.getColumnFamilyStore("Standard1");
    CellNameType type = notDurableKs.getColumnFamilyStore("Standard1").getComparator();
    Mutation rm;
    DecoratedKey dk = Util.dk("key1");

    // add data
    rm = new Mutation("NoCommitlogSpace", dk.getKey());
    rm.add("Standard1", Util.cellname("Column1"), ByteBufferUtil.bytes("abcd"), 0);
    rm.apply();

    ReadCommand command = new SliceByNamesReadCommand("NoCommitlogSpace", dk.getKey(), "Standard1", System.currentTimeMillis(), new NamesQueryFilter(FBUtilities.singleton(Util.cellname("Column1"), type)));
    Row row = command.getRow(notDurableKs);
    Cell col = row.cf.getColumn(Util.cellname("Column1"));
    Assert.assertEquals(col.value(), ByteBuffer.wrap("abcd".getBytes()));
    cfs.truncateBlocking();
    DatabaseDescriptor.setAutoSnapshot(prevAutoSnapshot);
    row = command.getRow(notDurableKs);
    Assert.assertEquals(null, row.cf);
}
 
Example 3
Source File: ColumnFamilyStoreTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Test
public void testCassandra6778() throws CharacterCodingException
{
    String cfname = "StandardInteger1";
    Keyspace keyspace = Keyspace.open("Keyspace1");
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);

    // insert two columns that represent the same integer but have different binary forms (the
    // second one is padded with extra zeros)
    Mutation rm = new Mutation("Keyspace1", ByteBufferUtil.bytes("k1"));
    CellName column1 = cellname(ByteBuffer.wrap(new byte[]{1}));
    rm.add(cfname, column1, ByteBufferUtil.bytes("data1"), 1);
    rm.apply();
    cfs.forceBlockingFlush();

    rm = new Mutation("Keyspace1", ByteBufferUtil.bytes("k1"));
    CellName column2 = cellname(ByteBuffer.wrap(new byte[]{0, 0, 1}));
    rm.add(cfname, column2, ByteBufferUtil.bytes("data2"), 2);
    rm.apply();
    cfs.forceBlockingFlush();

    // fetch by the first column name; we should get the second version of the column value
    SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(
        "Keyspace1", ByteBufferUtil.bytes("k1"), cfname, System.currentTimeMillis(),
        new NamesQueryFilter(FBUtilities.singleton(column1, cfs.getComparator())));

    ColumnFamily cf = cmd.getRow(keyspace).cf;
    assertEquals(1, cf.getColumnCount());
    Cell cell = cf.getColumn(column1);
    assertEquals("data2", ByteBufferUtil.string(cell.value()));
    assertEquals(column2, cell.name());

    // fetch by the second column name; we should get the second version of the column value
    cmd = new SliceByNamesReadCommand(
        "Keyspace1", ByteBufferUtil.bytes("k1"), cfname, System.currentTimeMillis(),
        new NamesQueryFilter(FBUtilities.singleton(column2, cfs.getComparator())));

    cf = cmd.getRow(keyspace).cf;
    assertEquals(1, cf.getColumnCount());
    cell = cf.getColumn(column2);
    assertEquals("data2", ByteBufferUtil.string(cell.value()));
    assertEquals(column2, cell.name());
}