本文整理汇总了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() + "])";
}
示例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());
}
示例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());
}
示例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());
}
示例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();
}
示例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();
}
示例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();
}