当前位置: 首页>>代码示例>>Java>>正文


Java Util.range方法代码示例

本文整理汇总了Java中org.apache.cassandra.Util.range方法的典型用法代码示例。如果您正苦于以下问题:Java Util.range方法的具体用法?Java Util.range怎么用?Java Util.range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.cassandra.Util的用法示例。


在下文中一共展示了Util.range方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testIndexUpdateOverwritingExpiringColumns

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testIndexUpdateOverwritingExpiringColumns() throws Exception
{
    // see CASSANDRA-7268
    Keyspace keyspace = Keyspace.open("Keyspace2");

    // create a row and update the birthdate value with an expiring column
    Mutation rm;
    rm = new Mutation("Keyspace2", ByteBufferUtil.bytes("k100"));
    rm.add("Indexed1", cellname("birthdate"), ByteBufferUtil.bytes(100L), 1, 1000);
    rm.apply();

    IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), Operator.EQ, ByteBufferUtil.bytes(100L));
    List<IndexExpression> clause = Arrays.asList(expr);
    IDiskAtomFilter filter = new IdentityQueryFilter();
    Range<RowPosition> range = Util.range("", "");
    List<Row> rows = keyspace.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
    assertEquals(1, rows.size());

    // requires a 1s sleep because we calculate local expiry time as (now() / 1000) + ttl
    TimeUnit.SECONDS.sleep(1);

    // now overwrite with the same name/value/ttl, but the local expiry time will be different
    rm = new Mutation("Keyspace2", ByteBufferUtil.bytes("k100"));
    rm.add("Indexed1", cellname("birthdate"), ByteBufferUtil.bytes(100L), 1, 1000);
    rm.apply();

    rows = keyspace.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
    assertEquals(1, rows.size());

    // check that modifying the indexed value using the same timestamp behaves as expected
    rm = new Mutation("Keyspace2", ByteBufferUtil.bytes("k101"));
    rm.add("Indexed1", cellname("birthdate"), ByteBufferUtil.bytes(101L), 1, 1000);
    rm.apply();

    expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), Operator.EQ, ByteBufferUtil.bytes(101L));
    clause = Arrays.asList(expr);
    rows = keyspace.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
    assertEquals(1, rows.size());

    TimeUnit.SECONDS.sleep(1);
    rm = new Mutation("Keyspace2", ByteBufferUtil.bytes("k101"));
    rm.add("Indexed1", cellname("birthdate"), ByteBufferUtil.bytes(102L), 1, 1000);
    rm.apply();
    // search for the old value
    rows = keyspace.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
    assertEquals(0, rows.size());
    // and for the new
    expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), Operator.EQ, ByteBufferUtil.bytes(102L));
    clause = Arrays.asList(expr);
    rows = keyspace.getColumnFamilyStore("Indexed1").search(range, clause, filter, 100);
    assertEquals(1, rows.size());
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:54,代码来源:ColumnFamilyStoreTest.java

示例2: testDeleteCompositeIndex

import org.apache.cassandra.Util; //导入方法依赖的package包/类
@Test
public void testDeleteCompositeIndex() throws Exception
{
    String keySpace = "Keyspace2";
    String cfName = "Indexed3"; // has gcGrace 0

    Keyspace keyspace = Keyspace.open(keySpace);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
    cfs.truncateBlocking();

    ByteBuffer rowKey = ByteBufferUtil.bytes("k1");
    ByteBuffer clusterKey = ByteBufferUtil.bytes("ck1");
    ByteBuffer colName = ByteBufferUtil.bytes("col1");

    CellNameType baseComparator = cfs.getComparator();
    CellName compositeName = baseComparator.makeCellName(clusterKey, colName);

    ByteBuffer val1 = ByteBufferUtil.bytes("v2");

    // Insert indexed value.
    Mutation rm;
    rm = new Mutation(keySpace, rowKey);
    rm.add(cfName, compositeName, val1, 0);
    rm.apply();

    // Now delete the value and flush too.
    rm = new Mutation(keySpace, rowKey);
    rm.delete(cfName, 1);
    rm.apply();

    // We want the data to be gcable, but even if gcGrace == 0, we still need to wait 1 second
    // since we won't gc on a tie.
    try { Thread.sleep(1000); } catch (Exception e) {}

    // Read the index and we check we do get no value (and no NPE)
    // Note: the index will return the entry because it hasn't been deleted (we
    // haven't read yet nor compacted) but the data read itself will return null
    IndexExpression expr = new IndexExpression(colName, Operator.EQ, val1);
    List<IndexExpression> clause = Arrays.asList(expr);
    IDiskAtomFilter filter = new IdentityQueryFilter();
    Range<RowPosition> range = Util.range("", "");
    List<Row> rows = keyspace.getColumnFamilyStore(cfName).search(range, clause, filter, 100);
    assertEquals(0, rows.size());
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:45,代码来源:ColumnFamilyStoreTest.java


注:本文中的org.apache.cassandra.Util.range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。