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


Java CounterContext.ContextState方法代码示例

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


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

示例1: apply

import org.apache.cassandra.db.context.CounterContext; //导入方法依赖的package包/类
@Override
public String apply(ColumnDefinition c, List<Object> params) {
    CounterContext.ContextState state = CounterContext.ContextState.wrap(value);
    StringBuilder buf = new StringBuilder();
    while (state.hasRemaining()) {
        if (buf.length() != 0) {
            buf.append(", ");
        }
        int type = 'r';
        if (state.isGlobal()) {
            type = 'g';
        }
        if (state.isLocal()) {
            type = 'l';
        }
        buf.append('(').append(type).append(',').append(getUUID(state.getCounterId().bytes())).append(',')
                .append(state.getClock()).append(',').append(state.getCount()).append(')');
        state.moveToNext();
    }
    return " = SCYLLA_COUNTER_SHARD_LIST([" + buf.toString() + "])";
}
 
开发者ID:scylladb,项目名称:scylla-tools-java,代码行数:22,代码来源:SSTableToCQL.java

示例2: testSerializeDeserialize

import org.apache.cassandra.db.context.CounterContext; //导入方法依赖的package包/类
@Test
public void testSerializeDeserialize() throws IOException
{
    CounterContext.ContextState state = CounterContext.ContextState.allocate(0, 2, 2);
    state.writeRemote(CounterId.fromInt(1), 4L, 4L);
    state.writeLocal(CounterId.fromInt(2), 4L, 4L);
    state.writeRemote(CounterId.fromInt(3), 4L, 4L);
    state.writeLocal(CounterId.fromInt(4), 4L, 4L);

    CellNameType type = new SimpleDenseCellNameType(UTF8Type.instance);
    CounterCell original = new BufferCounterCell(cellname("x"), state.context, 1L);
    byte[] serialized;
    try (DataOutputBuffer bufOut = new DataOutputBuffer())
    {
        type.columnSerializer().serialize(original, bufOut);
        serialized = bufOut.getData();
    }


    ByteArrayInputStream bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterCell deserialized = (CounterCell) type.columnSerializer().deserialize(new DataInputStream(bufIn));
    Assert.assertEquals(original, deserialized);

    bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterCell deserializedOnRemote = (CounterCell) type.columnSerializer().deserialize(new DataInputStream(bufIn), ColumnSerializer.Flag.FROM_REMOTE);
    Assert.assertEquals(deserializedOnRemote.name(), original.name());
    Assert.assertEquals(deserializedOnRemote.total(), original.total());
    Assert.assertEquals(deserializedOnRemote.value(), cc.clearAllLocal(original.value()));
    Assert.assertEquals(deserializedOnRemote.timestamp(), deserialized.timestamp());
    Assert.assertEquals(deserializedOnRemote.timestampOfLastDelete(), deserialized.timestampOfLastDelete());
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:32,代码来源:CounterCellTest.java

示例3: testSerializeDeserialize

import org.apache.cassandra.db.context.CounterContext; //导入方法依赖的package包/类
@Test
public void testSerializeDeserialize() throws IOException
{
    Allocator allocator = HeapAllocator.instance;
    CounterContext.ContextState state = CounterContext.ContextState.allocate(0, 2, 2, allocator);
    state.writeRemote(CounterId.fromInt(1), 4L, 4L);
    state.writeLocal(CounterId.fromInt(2), 4L, 4L);
    state.writeRemote(CounterId.fromInt(3), 4L, 4L);
    state.writeLocal(CounterId.fromInt(4), 4L, 4L);

    CellNameType type = new SimpleDenseCellNameType(UTF8Type.instance);
    CounterCell original = new CounterCell(cellname("x"), state.context, 1L);
    byte[] serialized;
    try (DataOutputBuffer bufOut = new DataOutputBuffer())
    {
        type.columnSerializer().serialize(original, bufOut);
        serialized = bufOut.getData();
    }


    ByteArrayInputStream bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterCell deserialized = (CounterCell) type.columnSerializer().deserialize(new DataInputStream(bufIn));
    Assert.assertEquals(original, deserialized);

    bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterCell deserializedOnRemote = (CounterCell) type.columnSerializer().deserialize(new DataInputStream(bufIn), ColumnSerializer.Flag.FROM_REMOTE);
    Assert.assertEquals(deserializedOnRemote.name(), original.name());
    Assert.assertEquals(deserializedOnRemote.total(), original.total());
    Assert.assertEquals(deserializedOnRemote.value(), cc.clearAllLocal(original.value()));
    Assert.assertEquals(deserializedOnRemote.timestamp(), deserialized.timestamp());
    Assert.assertEquals(deserializedOnRemote.timestampOfLastDelete(), deserialized.timestampOfLastDelete());
}
 
开发者ID:mafernandez-stratio,项目名称:cassandra-cqlMod,代码行数:33,代码来源:CounterCellTest.java

示例4: testSerializeDeserialize

import org.apache.cassandra.db.context.CounterContext; //导入方法依赖的package包/类
@Test
public void testSerializeDeserialize() throws IOException
{
    CounterContext.ContextState state = CounterContext.ContextState.allocate(0, 2, 2);
    state.writeRemote(CounterId.fromInt(1), 4L, 4L);
    state.writeLocal(CounterId.fromInt(2), 4L, 4L);
    state.writeRemote(CounterId.fromInt(3), 4L, 4L);
    state.writeLocal(CounterId.fromInt(4), 4L, 4L);

    CellNameType type = new SimpleDenseCellNameType(UTF8Type.instance);
    CounterCell original = new CounterCell(cellname("x"), state.context, 1L);
    byte[] serialized;
    try (DataOutputBuffer bufOut = new DataOutputBuffer())
    {
        type.columnSerializer().serialize(original, bufOut);
        serialized = bufOut.getData();
    }


    ByteArrayInputStream bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterCell deserialized = (CounterCell) type.columnSerializer().deserialize(new DataInputStream(bufIn));
    Assert.assertEquals(original, deserialized);

    bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterCell deserializedOnRemote = (CounterCell) type.columnSerializer().deserialize(new DataInputStream(bufIn), ColumnSerializer.Flag.FROM_REMOTE);
    Assert.assertEquals(deserializedOnRemote.name(), original.name());
    Assert.assertEquals(deserializedOnRemote.total(), original.total());
    Assert.assertEquals(deserializedOnRemote.value(), cc.clearAllLocal(original.value()));
    Assert.assertEquals(deserializedOnRemote.timestamp(), deserialized.timestamp());
    Assert.assertEquals(deserializedOnRemote.timestampOfLastDelete(), deserialized.timestampOfLastDelete());
}
 
开发者ID:rajath26,项目名称:cassandra-trunk,代码行数:32,代码来源:CounterCellTest.java

示例5: testLegacyCounterShardTracking

import org.apache.cassandra.db.context.CounterContext; //导入方法依赖的package包/类
@Test
public void testLegacyCounterShardTracking()
{
    ColumnFamilyStore cfs = Keyspace.open("Keyspace1").getColumnFamilyStore("Counter1");

    // A cell with all shards
    CounterContext.ContextState state = CounterContext.ContextState.allocate(1, 1, 1);
    state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
    state.writeLocal(CounterId.fromInt(2), 1L, 1L);
    state.writeRemote(CounterId.fromInt(3), 1L, 1L);
    ColumnFamily cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new BufferCounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").getKey(), cells).apply();
    cfs.forceBlockingFlush();
    assertTrue(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();

    // A cell with global and remote shards
    state = CounterContext.ContextState.allocate(0, 1, 1);
    state.writeLocal(CounterId.fromInt(2), 1L, 1L);
    state.writeRemote(CounterId.fromInt(3), 1L, 1L);
    cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new BufferCounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").getKey(), cells).apply();
    cfs.forceBlockingFlush();
    assertTrue(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();

    // A cell with global and local shards
    state = CounterContext.ContextState.allocate(1, 1, 0);
    state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
    state.writeLocal(CounterId.fromInt(2), 1L, 1L);
    cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new BufferCounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").getKey(), cells).apply();
    cfs.forceBlockingFlush();
    assertTrue(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();

    // A cell with global only
    state = CounterContext.ContextState.allocate(1, 0, 0);
    state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
    cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new BufferCounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").getKey(), cells).apply();
    cfs.forceBlockingFlush();
    assertFalse(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:50,代码来源:SSTableMetadataTest.java

示例6: testLegacyCounterShardTracking

import org.apache.cassandra.db.context.CounterContext; //导入方法依赖的package包/类
@Test
public void testLegacyCounterShardTracking()
{
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore("Counter1");

    // A cell with all shards
    CounterContext.ContextState state = CounterContext.ContextState.allocate(1, 1, 1);
    state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
    state.writeLocal(CounterId.fromInt(2), 1L, 1L);
    state.writeRemote(CounterId.fromInt(3), 1L, 1L);
    ColumnFamily cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new BufferCounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").getKey(), cells).applyUnsafe();
    cfs.forceBlockingFlush();
    assertTrue(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();

    // A cell with global and remote shards
    state = CounterContext.ContextState.allocate(0, 1, 1);
    state.writeLocal(CounterId.fromInt(2), 1L, 1L);
    state.writeRemote(CounterId.fromInt(3), 1L, 1L);
    cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new BufferCounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").getKey(), cells).applyUnsafe();
    cfs.forceBlockingFlush();
    assertTrue(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();

    // A cell with global and local shards
    state = CounterContext.ContextState.allocate(1, 1, 0);
    state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
    state.writeLocal(CounterId.fromInt(2), 1L, 1L);
    cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new BufferCounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").getKey(), cells).applyUnsafe();
    cfs.forceBlockingFlush();
    assertTrue(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();

    // A cell with global only
    state = CounterContext.ContextState.allocate(1, 0, 0);
    state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
    cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new BufferCounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").getKey(), cells).applyUnsafe();
    cfs.forceBlockingFlush();
    assertFalse(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();
}
 
开发者ID:daidong,项目名称:GraphTrek,代码行数:50,代码来源:SSTableMetadataTest.java

示例7: testLegacyCounterShardTracking

import org.apache.cassandra.db.context.CounterContext; //导入方法依赖的package包/类
@Test
public void testLegacyCounterShardTracking()
{
    ColumnFamilyStore cfs = Keyspace.open("Keyspace1").getColumnFamilyStore("Counter1");

    // A cell with all shards
    CounterContext.ContextState state = CounterContext.ContextState.allocate(1, 1, 1);
    state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
    state.writeLocal(CounterId.fromInt(2), 1L, 1L);
    state.writeRemote(CounterId.fromInt(3), 1L, 1L);
    ColumnFamily cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new CounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").key, cells).apply();
    cfs.forceBlockingFlush();
    assertTrue(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();

    // A cell with global and remote shards
    state = CounterContext.ContextState.allocate(0, 1, 1);
    state.writeLocal(CounterId.fromInt(2), 1L, 1L);
    state.writeRemote(CounterId.fromInt(3), 1L, 1L);
    cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new CounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").key, cells).apply();
    cfs.forceBlockingFlush();
    assertTrue(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();

    // A cell with global and local shards
    state = CounterContext.ContextState.allocate(1, 1, 0);
    state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
    state.writeLocal(CounterId.fromInt(2), 1L, 1L);
    cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new CounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").key, cells).apply();
    cfs.forceBlockingFlush();
    assertTrue(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();

    // A cell with global only
    state = CounterContext.ContextState.allocate(1, 0, 0);
    state.writeGlobal(CounterId.fromInt(1), 1L, 1L);
    cells = ArrayBackedSortedColumns.factory.create(cfs.metadata);
    cells.addColumn(new CounterCell(cellname("col"), state.context, 1L, Long.MIN_VALUE));
    new Mutation(Util.dk("k").key, cells).apply();
    cfs.forceBlockingFlush();
    assertFalse(cfs.getSSTables().iterator().next().getSSTableMetadata().hasLegacyCounterShards);
    cfs.truncateBlocking();
}
 
开发者ID:rajath26,项目名称:cassandra-trunk,代码行数:50,代码来源:SSTableMetadataTest.java


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