private void handleAggregateCounterRow( Mutator<ByteBuffer> m, String key, long column, long value, UUID applicationId ) { if ( logger.isTraceEnabled() ) { logger.trace( "HACR: aggregateRow for app {} with key {} column {} and value {}", applicationId, key, column, value ); } if ( "o".equals( counterType ) || "p".equals( counterType ) ) { if ( m != null ) { HCounterColumn<Long> c = createCounterColumn( column, value, le ); m.addCounter( bytebuffer( key ), APPLICATION_AGGREGATE_COUNTERS.toString(), c ); } } if ( "n".equals( counterType ) || "p".equals( counterType ) ) { // create and add Count PrefixedSerializer ps = new PrefixedSerializer( applicationId, ue, se ); batcher.add( new Count( APPLICATION_AGGREGATE_COUNTERS.toString(), ps.toByteBuffer( key ), column, value ) ); } }
Mutator<String> m = createMutator(ko, se); MutationResult mr = m.insertCounter("testInsertGetRemoveCounter", COUNTER_CF, createCounterColumn("testInsertGetRemoveCounter_name", 25));
private Mutator<ByteBuffer> batchIncrementEntityCounter( Mutator<ByteBuffer> m, UUID entityId, String name, Long value, long timestamp, UUID applicationId ) { if ( logger.isTraceEnabled() ) { logger.trace( "BIEC: Incrementing property {} of entity {} by value {}", name, entityId, value ); } addInsertToMutator( m, ENTITY_DICTIONARIES, key( entityId, DICTIONARY_COUNTERS ), name, null, timestamp ); if ( "o".equals( counterType ) || "p".equals( counterType ) ) { HCounterColumn<String> c = createCounterColumn( name, value ); m.addCounter( bytebuffer( entityId ), ENTITY_COUNTERS.toString(), c ); } if ( "n".equals( counterType ) || "p".equals( counterType ) ) { PrefixedSerializer ps = new PrefixedSerializer( applicationId, ue, ue ); batcher.add( new Count( ENTITY_COUNTERS.toString(), ps.toByteBuffer( entityId ), name, value ) ); } return m; }
public Mutator<ByteBuffer> batchIncrementQueueCounter( Mutator<ByteBuffer> m, UUID queueId, String name, long value, long timestamp, UUID applicationId ) { if ( logger.isTraceEnabled() ) { logger.trace( "BIQC: Incrementing property {} of queue {} by value {}", name, queueId, value ); } m.addInsertion( bytebuffer( key( queueId, DICTIONARY_COUNTERS ).toString() ), QueuesCF.QUEUE_DICTIONARIES.toString(), createColumn( name, ByteBuffer.allocate( 0 ), timestamp, se, be ) ); if ( "o".equals( counterType ) || "p".equals( counterType ) ) { HCounterColumn<String> c = createCounterColumn( name, value ); ByteBuffer keybytes = bytebuffer( queueId ); m.addCounter( keybytes, QueuesCF.COUNTERS.toString(), c ); } if ( "n".equals( counterType ) || "p".equals( counterType ) ) { PrefixedSerializer ps = new PrefixedSerializer( applicationId, ue, ue ); batcher.add( new Count( QueuesCF.COUNTERS.toString(), ps.toByteBuffer( queueId ), name, value ) ); } return m; }
@Override public <N> HCounterColumn<N> createCounterColumn(N name, long value, Serializer<N> nameSerializer) { return HFactory.createCounterColumn(name, value, nameSerializer); }
@Override public HCounterColumn<String> createCounterColumn(String name, long value) { return HFactory.createCounterColumn(name, value); }
/** * Convenient method for creating a counter column with a String name and long value */ public static HCounterColumn<String> createCounterColumn(String name, long value) { StringSerializer se = StringSerializer.get(); return createCounterColumn(name, value, se); }
@Before public void setupCase() { cluster = getOrCreateCluster("MyCluster", "127.0.0.1:9170"); keyspace = createKeyspace(KEYSPACE, cluster); createMutator(keyspace, se) .addCounter("ranageSlicesCounterTest_key1", cf, createCounterColumn("alpha", 1L)) .addCounter("ranageSlicesCounterTest_key1", cf, createCounterColumn("beta", 2L)) .addCounter("ranageSlicesCounterTest_key2", cf, createCounterColumn("alpha", 1L)) .addCounter("ranageSlicesCounterTest_key2", cf, createCounterColumn("beta", 2L)) .addCounter("ranageSlicesCounterTest_key3", cf, createCounterColumn("alpha", 1L)) .addCounter("ranageSlicesCounterTest_key3", cf, createCounterColumn("beta", 2L)) .addCounter("ranageSlicesCounterTest_key4", cf, createCounterColumn("alpha", 1L)) .addCounter("ranageSlicesCounterTest_key4", cf, createCounterColumn("beta", 2L)) .addCounter("ranageSlicesCounterTest_key5", cf, createCounterColumn("alpha", 1L)) .addCounter("ranageSlicesCounterTest_key5", cf, createCounterColumn("beta", 2L)) .addCounter("ranageSlicesCounterTest_key6", cf, createCounterColumn("alpha", 1L)) .addCounter("ranageSlicesCounterTest_key6", cf, createCounterColumn("beta", 2L)) .execute(); }
private TestCleanupDescriptor insertSuperCountColumns(String cf, int rowCount, String rowPrefix, int scCount, String scPrefix) { Mutator<String> m = createMutator(ko, se); for (int i = 0; i < rowCount; ++i) { for (int j = 0; j < scCount; ++j) { @SuppressWarnings("unchecked") HCounterSuperColumn<String, String> sc = createCounterSuperColumn(scPrefix + j, Arrays.asList( createCounterColumn("c0" + i + j, i + j), createCounterColumn("c1" + 1 + j, i + j)), se, se); m.addCounter(rowPrefix + i, cf, sc); } } m.execute(); return new TestCleanupDescriptor(cf, rowCount, rowPrefix, scCount, scPrefix); }
@Override public <N> HCounterColumn<N> createCounterColumn(N name, long value, Serializer<N> nameSerializer) { return HFactory.createCounterColumn(name, value, nameSerializer); }
@Override public HCounterColumn<String> createCounterColumn(String name, long value) { return HFactory.createCounterColumn(name, value); }
m.addCounter(KEY, CF, createCounterColumn("a" + i, 1, se)); m.addCounter(KEY, CF, createCounterColumn("b" + i, 1, se)); m.addCounter(KEY, CF, createCounterColumn("c" + i, 1, se));
@Before public void setUp() { cluster = getOrCreateCluster("Test Cluster", "127.0.0.1:9170"); keyspace = createKeyspace("Keyspace1", cluster); Mutator<String> m = createMutator(keyspace, se); for (int i = 0; i < 1000; i++) { m.addCounter(KEY, CF, createCounterColumn(TimeUUIDUtils.getUniqueTimeUUIDinMillis(), 1, us)); } m.execute(); }
@Test public void testCounterMutation() { // Insert a counter mutation Mutator<String> m = createMutator(ko, se); m.addCounter("testCounterMutation", COUNTER_CF, createCounterColumn("testCounterMutation_col_name", 5)); m.execute(); // Check the value assertEquals(new Long(5), readCounterValue("testCounterMutation", COUNTER_CF, "testCounterMutation_col_name")); // Delete m = createMutator(ko, se); m.addCounterDeletion("testCounterMutation", COUNTER_CF); m.execute(); // Check the value again. IT should be deleted. assertNull(readCounterValue("testCounterMutation", COUNTER_CF, "testCounterMutation_col_name")); }
/** * Convenient method for creating a counter column with a String name and long value */ public static HCounterColumn<String> createCounterColumn(String name, long value) { StringSerializer se = StringSerializer.get(); return createCounterColumn(name, value, se); }
/** * Convenient method for creating a counter column with a String name and long value */ public static HCounterColumn<String> createCounterColumn(String name, long value) { StringSerializer se = StringSerializer.get(); return createCounterColumn(name, value, se); }
@Test public void testInsertCounter() { Mutator<String> m = createMutator(keyspace, se); MutationResult mr = m.insertCounter("k", "Counter1", createCounterColumn("name", 5)); assertTrue("Execution time on single counter insert should be > 0", mr.getExecutionTimeMicro() > 0); assertTrue("Should have operated on a host", mr.getHostUsed() != null); CounterQuery<String, String> counter = new ThriftCounterColumnQuery<String,String>(keyspace, se, se); counter.setColumnFamily("Counter1").setKey("k").setName("name"); assertEquals(new Long(5), counter.execute().get().getValue()); }
mutator.addCounter("testCounterSliceQuery_key", cf, createCounterColumn("" + i, i));
@Override public void set(final K key, final Long value) { createMutator(_keyspace, _serializer_k).insertCounter(key, _cf_name, createCounterColumn(COLUMN_NAME_AS_STRING, value)); }
Mutator<String> mutator = createMutator(keyspace, ss); for (int i = 1; i <= 10; i++) { mutator.addCounter(key, cf, createCounterColumn("" + i, i));