Java Code Examples for org.apache.cassandra.utils.UUIDGen#getTimeUUID()
The following examples show how to use
org.apache.cassandra.utils.UUIDGen#getTimeUUID() .
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: AuditLogSerializationTest.java From usergrid with Apache License 2.0 | 6 votes |
@Test public void testRecordAuditLog() throws Exception { CassandraClient cassandraClient = getInjector().getInstance( CassandraClientImpl.class ); AuditLogSerialization logSerialization = getInjector().getInstance( AuditLogSerialization.class ); // record some audit logs for a message UUID messageId = UUIDGen.getTimeUUID(); String queueName = "alst_queue_" + RandomStringUtils.randomAlphanumeric( 15 ); String source = RandomStringUtils.randomAlphanumeric( 15 ); String dest = RandomStringUtils.randomAlphanumeric( 15 ); logSerialization.recordAuditLog( AuditLog.Action.GET, AuditLog.Status.SUCCESS, queueName, dest, messageId, UUIDGen.getTimeUUID() ); // get audit logs for that message Result<AuditLog> result = logSerialization.getAuditLogs( messageId ); Assert.assertEquals( 1, result.getEntities().size() ); }
Example 2
Source File: ClientUtilsTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** Exercises the classes in the clientutil jar to expose missing dependencies. */ @Test public void test() { AsciiSerializer.instance.deserialize(AsciiSerializer.instance.serialize("string")); BooleanSerializer.instance.deserialize(BooleanSerializer.instance.serialize(true)); BytesSerializer.instance.deserialize(BytesSerializer.instance.serialize(ByteBuffer.wrap("string".getBytes()))); Date date = new Date(System.currentTimeMillis()); ByteBuffer dateBB = TimestampSerializer.instance.serialize(date); TimestampSerializer.instance.deserialize(dateBB); DecimalSerializer.instance.deserialize(DecimalSerializer.instance.serialize(new BigDecimal(1))); DoubleSerializer.instance.deserialize(DoubleSerializer.instance.serialize(new Double(1.0d))); FloatSerializer.instance.deserialize(FloatSerializer.instance.serialize(new Float(1.0f))); Int32Serializer.instance.deserialize(Int32Serializer.instance.serialize(1)); IntegerSerializer.instance.deserialize(IntegerSerializer.instance.serialize(new BigInteger("1"))); LongSerializer.instance.deserialize(LongSerializer.instance.serialize(1L)); UTF8Serializer.instance.deserialize(UTF8Serializer.instance.serialize("string")); // UUIDGen UUID uuid = UUIDGen.getTimeUUID(); UUIDSerializer.instance.deserialize(UUIDSerializer.instance.serialize(uuid)); }
Example 3
Source File: PrepareMessage.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public Message.Response execute(QueryState state) { try { UUID tracingId = null; if (isTracingRequested()) { tracingId = UUIDGen.getTimeUUID(); state.prepareTracingSession(tracingId); } if (state.traceNextQuery()) { state.createTracingSession(); Tracing.instance.begin("Preparing CQL3 query", ImmutableMap.of("query", query)); } Message.Response response = state.getClientState().getCQLQueryHandler().prepare(query, state); if (tracingId != null) response.setTracingId(tracingId); return response; } catch (Exception e) { JVMStabilityInspector.inspectThrowable(e); return ErrorMessage.fromException(e); } finally { Tracing.instance.stopSession(); } }
Example 4
Source File: TransferLogSerializationTest.java From usergrid with Apache License 2.0 | 5 votes |
@Test public void removeTransferLog() throws Exception { TransferLogSerialization logSerialization = getInjector().getInstance( TransferLogSerialization.class ); CassandraClient cassandraClient = getInjector().getInstance( CassandraClientImpl.class ); String queueName = "tlst_queue_" + RandomStringUtils.randomAlphanumeric( 15 ); String source = RandomStringUtils.randomAlphanumeric( 15 ); String dest = RandomStringUtils.randomAlphanumeric( 15 ); UUID messageId = UUIDGen.getTimeUUID(); logSerialization.recordTransferLog( queueName, source, dest, messageId ); List<TransferLog> allLogs = getTransferLogs( logSerialization ); // we only want entities for our queue List<TransferLog> logs = allLogs.stream() .filter( log -> log.getQueueName().equals( queueName ) ).collect( Collectors.toList() ); Assert.assertEquals( 1, logs.size()); logSerialization.removeTransferLog( queueName, source, dest, messageId ); List<TransferLog> all = getTransferLogs( logSerialization ); logs = all.stream() .filter( log -> log.getQueueName().equals( queueName ) ).collect( Collectors.toList() ); Assert.assertEquals( 0, logs.size()); try { logSerialization.removeTransferLog( queueName, source, dest, messageId ); Assert.fail("Removing non-existent log should throw exception"); } catch ( QakkaException expected ) { // success! } }
Example 5
Source File: AuditLogSerializationTest.java From usergrid with Apache License 2.0 | 5 votes |
@Test public void testGetAuditLogs() throws Exception { CassandraClient cassandraClient = getInjector().getInstance( CassandraClientImpl.class ); AuditLogSerialization logSerialization = getInjector().getInstance( AuditLogSerialization.class ); // record some audit logs for a message UUID messageId = UUIDGen.getTimeUUID(); String queueName = "alst_queue_" + RandomStringUtils.randomAlphanumeric( 15 ); String source = RandomStringUtils.randomAlphanumeric( 15 ); String dest = RandomStringUtils.randomAlphanumeric( 15 ); int numLogs = 10; UUID queueMessageId1 = UUIDGen.getTimeUUID(); for ( int i=0; i<numLogs; i++ ) { logSerialization.recordAuditLog( AuditLog.Action.GET, AuditLog.Status.SUCCESS, queueName, dest, messageId, queueMessageId1 ); Thread.sleep(5); } UUID queueMessageId2 = UUIDGen.getTimeUUID(); for ( int i=0; i<numLogs; i++ ) { logSerialization.recordAuditLog( AuditLog.Action.GET, AuditLog.Status.SUCCESS, queueName, dest, messageId, queueMessageId2 ); Thread.sleep(5); } UUID queueMessageId3 = UUIDGen.getTimeUUID(); for ( int i=0; i<numLogs; i++ ) { logSerialization.recordAuditLog( AuditLog.Action.GET, AuditLog.Status.SUCCESS, queueName, dest, messageId, queueMessageId3 ); Thread.sleep(5); } // test that we have 3 X number of logs for the messageId Result<AuditLog> result = logSerialization.getAuditLogs( messageId ); Assert.assertEquals( numLogs * 3, result.getEntities().size() ); }
Example 6
Source File: TimeUUIDTypeTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testEquality() { UUID a = UUIDGen.getTimeUUID(); UUID b = new UUID(a.getMostSignificantBits(), a.getLeastSignificantBits()); timeUUIDType.validate(ByteBuffer.wrap(UUIDGen.decompose(a))); timeUUIDType.validate(ByteBuffer.wrap(UUIDGen.decompose(b))); assertEquals(0, timeUUIDType.compare(ByteBuffer.wrap(UUIDGen.decompose(a)), ByteBuffer.wrap(UUIDGen.decompose(b)))); }
Example 7
Source File: UUIDTypeTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testCompare() { UUID t1 = UUIDGen.getTimeUUID(); UUID t2 = UUIDGen.getTimeUUID(); testCompare(null, t2, -1); testCompare(t1, null, 1); testCompare(t1, t2, -1); testCompare(t1, t1, 0); testCompare(t2, t2, 0); UUID nullId = new UUID(0, 0); testCompare(nullId, t1, -1); testCompare(t2, nullId, 1); testCompare(nullId, nullId, 0); for (int test = 1; test < 32; test++) { UUID r1 = UUID.randomUUID(); UUID r2 = UUID.randomUUID(); testCompare(r1, r2, compareUUID(r1, r2)); testCompare(r1, r1, 0); testCompare(r2, r2, 0); testCompare(t1, r1, -1); testCompare(r2, t2, 1); } }
Example 8
Source File: UUIDTypeTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testTimeEquality() { UUID a = UUIDGen.getTimeUUID(); UUID b = new UUID(a.getMostSignificantBits(), a.getLeastSignificantBits()); assertEquals(0, uuidType.compare(bytebuffer(a), bytebuffer(b))); }
Example 9
Source File: QueueActorServiceTest.java From usergrid with Apache License 2.0 | 4 votes |
@Test public void testQueueMessageCounter() throws InterruptedException { Injector injector = getInjector(); ActorSystemFig actorSystemFig = injector.getInstance( ActorSystemFig.class ); String region = actorSystemFig.getRegionLocal(); // App app = injector.getInstance( App.class ); // app.start("localhost", getNextAkkaPort(), region); DistributedQueueService distributedQueueService = injector.getInstance( DistributedQueueService.class ); QueueMessageSerialization serialization = injector.getInstance( QueueMessageSerialization.class ); TransferLogSerialization xferLogSerialization = injector.getInstance( TransferLogSerialization.class ); QueueMessageManager queueMessageManager = injector.getInstance( QueueMessageManager.class ); String queueName = "queue_testGetMultipleQueueMessages_" + UUID.randomUUID(); QueueManager queueManager = injector.getInstance( QueueManager.class ); try { queueManager.createQueue( new Queue( queueName, "test-type", region, region, 0L, 5, 10, null ) ); UUID messageId = UUIDGen.getTimeUUID(); final String data = "my test data"; final DatabaseQueueMessageBody messageBody = new DatabaseQueueMessageBody( DataType.serializeValue( data, ProtocolVersion.NEWEST_SUPPORTED ), "text/plain" ); serialization.writeMessageData( messageId, messageBody ); xferLogSerialization.recordTransferLog( queueName, actorSystemFig.getRegionLocal(), region, messageId ); distributedQueueService.sendMessageToRegion( queueName, region, region, messageId, null, null ); DatabaseQueueMessage.Type type = DatabaseQueueMessage.Type.DEFAULT; Thread.sleep(5000); int maxRetries = 10; int retries = 0; long count = 0; while (retries++ < maxRetries) { distributedQueueService.refresh(); count = queueMessageManager.getQueueDepth( queueName, type ); if ( count > 0 ) { break; } Thread.sleep( 1000 ); } Thread.sleep( 1000 ); Assert.assertEquals( 1, queueMessageManager.getQueueDepth( queueName, type ) ); distributedQueueService.shutdown(); } finally { queueManager.deleteQueue( queueName ); } }
Example 10
Source File: QueryMessage.java From stratio-cassandra with Apache License 2.0 | 4 votes |
public Message.Response execute(QueryState state) { try { if (options.getPageSize() == 0) throw new ProtocolException("The page size cannot be 0"); UUID tracingId = null; if (isTracingRequested()) { tracingId = UUIDGen.getTimeUUID(); state.prepareTracingSession(tracingId); } if (state.traceNextQuery()) { state.createTracingSession(); ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("query", query); if (options.getPageSize() > 0) builder.put("page_size", Integer.toString(options.getPageSize())); Tracing.instance.begin("Execute CQL3 query", builder.build()); } Message.Response response = state.getClientState().getCQLQueryHandler().process(query, state, options); if (options.skipMetadata() && response instanceof ResultMessage.Rows) ((ResultMessage.Rows)response).result.metadata.setSkipMetadata(); if (tracingId != null) response.setTracingId(tracingId); return response; } catch (Exception e) { JVMStabilityInspector.inspectThrowable(e); if (!((e instanceof RequestValidationException) || (e instanceof RequestExecutionException))) logger.error("Unexpected error during query", e); return ErrorMessage.fromException(e); } finally { Tracing.instance.stopSession(); } }
Example 11
Source File: QueueActorServiceTest.java From usergrid with Apache License 2.0 | 4 votes |
@Test public void testGetMultipleQueueMessages() throws InterruptedException { Injector injector = getInjector(); ActorSystemFig actorSystemFig = injector.getInstance( ActorSystemFig.class ); String region = actorSystemFig.getRegionLocal(); // App app = injector.getInstance( App.class ); // app.start("localhost", getNextAkkaPort(), region); DistributedQueueService distributedQueueService = injector.getInstance( DistributedQueueService.class ); QueueMessageSerialization serialization = injector.getInstance( QueueMessageSerialization.class ); TransferLogSerialization xferLogSerialization = injector.getInstance( TransferLogSerialization.class ); QueueMessageManager queueMessageManager = injector.getInstance( QueueMessageManager.class ); String queueName = "queue_testGetMultipleQueueMessages_" + UUID.randomUUID(); QueueManager queueManager = injector.getInstance( QueueManager.class ); try { queueManager.createQueue( new Queue( queueName, "test-type", region, region, 0L, 5, 10, null ) ); for (int i = 0; i < 100; i++) { UUID messageId = UUIDGen.getTimeUUID(); final String data = "my test data"; final DatabaseQueueMessageBody messageBody = new DatabaseQueueMessageBody( DataType.serializeValue( data, ProtocolVersion.NEWEST_SUPPORTED ), "text/plain" ); serialization.writeMessageData( messageId, messageBody ); xferLogSerialization.recordTransferLog( queueName, actorSystemFig.getRegionLocal(), region, messageId ); distributedQueueService.sendMessageToRegion( queueName, region, region, messageId, null, null ); } DatabaseQueueMessage.Type type = DatabaseQueueMessage.Type.DEFAULT; int maxRetries = 30; int retries = 0; long count = 0; while (retries++ < maxRetries) { distributedQueueService.refresh(); count = queueMessageManager.getQueueDepth( queueName, type ); if ( count == 100 ) { break; } Thread.sleep( 1000 ); } Assert.assertEquals( 100, count ); Assert.assertEquals( 25, distributedQueueService.getNextMessages( queueName, 25 ).size() ); Assert.assertEquals( 75, queueMessageManager.getQueueDepth( queueName, type ) ); Assert.assertEquals( 25, distributedQueueService.getNextMessages( queueName, 25 ).size() ); Assert.assertEquals( 50, queueMessageManager.getQueueDepth( queueName, type ) ); Assert.assertEquals( 25, distributedQueueService.getNextMessages( queueName, 25 ).size() ); Assert.assertEquals( 25, queueMessageManager.getQueueDepth( queueName, type ) ); Assert.assertEquals( 25, distributedQueueService.getNextMessages( queueName, 25 ).size() ); Assert.assertEquals( 0, queueMessageManager.getQueueDepth( queueName, type ) ); distributedQueueService.shutdown(); } finally { queueManager.deleteQueue( queueName ); } }
Example 12
Source File: TimeUUIDs.java From stratio-cassandra with Apache License 2.0 | 4 votes |
@Override public UUID generate() { return UUIDGen.getTimeUUID(dateGen.generate().getTime(), clockSeqAndNode); }
Example 13
Source File: CFMetaData.java From stratio-cassandra with Apache License 2.0 | 4 votes |
private static CFMetaData internalFromThrift(CfDef cf_def, Collection<ColumnDefinition> previousCQLMetadata) throws InvalidRequestException, ConfigurationException { ColumnFamilyType cfType = ColumnFamilyType.create(cf_def.column_type); if (cfType == null) throw new InvalidRequestException("Invalid column type " + cf_def.column_type); applyImplicitDefaults(cf_def); try { AbstractType<?> rawComparator = TypeParser.parse(cf_def.comparator_type); AbstractType<?> subComparator = cfType == ColumnFamilyType.Standard ? null : cf_def.subcomparator_type == null ? BytesType.instance : TypeParser.parse(cf_def.subcomparator_type); AbstractType<?> fullRawComparator = makeRawAbstractType(rawComparator, subComparator); AbstractType<?> keyValidator = cf_def.isSetKey_validation_class() ? TypeParser.parse(cf_def.key_validation_class) : null; // Convert the REGULAR definitions from the input CfDef List<ColumnDefinition> defs = ColumnDefinition.fromThrift(cf_def.keyspace, cf_def.name, rawComparator, subComparator, cf_def.column_metadata); // Add the keyAlias if there is one, since that's on CQL metadata that thrift can actually change (for // historical reasons) boolean hasKeyAlias = cf_def.isSetKey_alias() && keyValidator != null && !(keyValidator instanceof CompositeType); if (hasKeyAlias) defs.add(ColumnDefinition.partitionKeyDef(cf_def.keyspace, cf_def.name, cf_def.key_alias, keyValidator, null)); // Now add any CQL metadata that we want to copy, skipping the keyAlias if there was one for (ColumnDefinition def : previousCQLMetadata) { // isPartOfCellName basically means 'is not just a CQL metadata' if (def.isPartOfCellName()) continue; if (def.kind == ColumnDefinition.Kind.PARTITION_KEY && hasKeyAlias) continue; defs.add(def); } CellNameType comparator = CellNames.fromAbstractType(fullRawComparator, calculateIsDense(fullRawComparator, defs)); UUID cfId = Schema.instance.getId(cf_def.keyspace, cf_def.name); if (cfId == null) cfId = UUIDGen.getTimeUUID(); CFMetaData newCFMD = new CFMetaData(cf_def.keyspace, cf_def.name, cfType, comparator, cfId); newCFMD.addAllColumnDefinitions(defs); if (keyValidator != null) newCFMD.keyValidator(keyValidator); if (cf_def.isSetGc_grace_seconds()) newCFMD.gcGraceSeconds(cf_def.gc_grace_seconds); if (cf_def.isSetMin_compaction_threshold()) newCFMD.minCompactionThreshold(cf_def.min_compaction_threshold); if (cf_def.isSetMax_compaction_threshold()) newCFMD.maxCompactionThreshold(cf_def.max_compaction_threshold); if (cf_def.isSetCompaction_strategy()) newCFMD.compactionStrategyClass(createCompactionStrategy(cf_def.compaction_strategy)); if (cf_def.isSetCompaction_strategy_options()) newCFMD.compactionStrategyOptions(new HashMap<>(cf_def.compaction_strategy_options)); if (cf_def.isSetBloom_filter_fp_chance()) newCFMD.bloomFilterFpChance(cf_def.bloom_filter_fp_chance); if (cf_def.isSetMemtable_flush_period_in_ms()) newCFMD.memtableFlushPeriod(cf_def.memtable_flush_period_in_ms); if (cf_def.isSetCaching() || cf_def.isSetCells_per_row_to_cache()) newCFMD.caching(CachingOptions.fromThrift(cf_def.caching, cf_def.cells_per_row_to_cache)); if (cf_def.isSetRead_repair_chance()) newCFMD.readRepairChance(cf_def.read_repair_chance); if (cf_def.isSetDefault_time_to_live()) newCFMD.defaultTimeToLive(cf_def.default_time_to_live); if (cf_def.isSetDclocal_read_repair_chance()) newCFMD.dcLocalReadRepairChance(cf_def.dclocal_read_repair_chance); if (cf_def.isSetMin_index_interval()) newCFMD.minIndexInterval(cf_def.min_index_interval); if (cf_def.isSetMax_index_interval()) newCFMD.maxIndexInterval(cf_def.max_index_interval); if (cf_def.isSetSpeculative_retry()) newCFMD.speculativeRetry(SpeculativeRetry.fromString(cf_def.speculative_retry)); if (cf_def.isSetTriggers()) newCFMD.triggers(TriggerDefinition.fromThrift(cf_def.triggers)); return newCFMD.comment(cf_def.comment) .defaultValidator(TypeParser.parse(cf_def.default_validation_class)) .compressionParameters(CompressionParameters.create(cf_def.compression_options)) .rebuild(); } catch (SyntaxException | MarshalException e) { throw new ConfigurationException(e.getMessage()); } }
Example 14
Source File: CassandraServer.java From stratio-cassandra with Apache License 2.0 | 4 votes |
public ByteBuffer trace_next_query() throws TException { UUID sessionId = UUIDGen.getTimeUUID(); state().getQueryState().prepareTracingSession(sessionId); return TimeUUIDType.instance.decompose(sessionId); }
Example 15
Source File: ExecuteMessage.java From stratio-cassandra with Apache License 2.0 | 4 votes |
public Message.Response execute(QueryState state) { try { QueryHandler handler = state.getClientState().getCQLQueryHandler(); ParsedStatement.Prepared prepared = handler.getPrepared(statementId); if (prepared == null) throw new PreparedQueryNotFoundException(statementId); options.prepare(prepared.boundNames); CQLStatement statement = prepared.statement; if (options.getPageSize() == 0) throw new ProtocolException("The page size cannot be 0"); UUID tracingId = null; if (isTracingRequested()) { tracingId = UUIDGen.getTimeUUID(); state.prepareTracingSession(tracingId); } if (state.traceNextQuery()) { state.createTracingSession(); ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); if (options.getPageSize() > 0) builder.put("page_size", Integer.toString(options.getPageSize())); // TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support. Tracing.instance.begin("Execute CQL3 prepared query", builder.build()); } Message.Response response = handler.processPrepared(statement, state, options); if (options.skipMetadata() && response instanceof ResultMessage.Rows) ((ResultMessage.Rows)response).result.metadata.setSkipMetadata(); if (tracingId != null) response.setTracingId(tracingId); return response; } catch (Exception e) { JVMStabilityInspector.inspectThrowable(e); return ErrorMessage.fromException(e); } finally { Tracing.instance.stopSession(); } }
Example 16
Source File: CFMetaData.java From stratio-cassandra with Apache License 2.0 | 2 votes |
/** * Create new ColumnFamily metadata with generated random ID. * When loading from existing schema, use CFMetaData * * @param keyspace keyspace name * @param name column family name * @param comp default comparator */ public CFMetaData(String keyspace, String name, ColumnFamilyType type, CellNameType comp) { this(keyspace, name, type, comp, UUIDGen.getTimeUUID()); }
Example 17
Source File: QueueActorServiceTest.java From usergrid with Apache License 2.0 | 2 votes |
@Test public void testBasicOperation() throws Exception { Injector injector = getInjector(); ActorSystemFig actorSystemFig = injector.getInstance( ActorSystemFig.class ); String region = actorSystemFig.getRegionLocal(); // App app = injector.getInstance( App.class ); // app.start( "localhost", getNextAkkaPort(), region ); DistributedQueueService distributedQueueService = injector.getInstance( DistributedQueueService.class ); QueueMessageSerialization serialization = injector.getInstance( QueueMessageSerialization.class ); String queueName = "testqueue_" + UUID.randomUUID(); QueueManager queueManager = injector.getInstance( QueueManager.class ); queueManager.createQueue( new Queue( queueName, "test-type", region, region, 0L, 5, 10, null )); try { // send 1 queue message, get back one queue message UUID messageId = UUIDGen.getTimeUUID(); final String data = "my test data"; final DatabaseQueueMessageBody messageBody = new DatabaseQueueMessageBody( DataType.serializeValue( data, ProtocolVersion.NEWEST_SUPPORTED ), "text/plain" ); serialization.writeMessageData( messageId, messageBody ); distributedQueueService.sendMessageToRegion( queueName, region, region, messageId, null, null ); distributedQueueService.refresh(); Thread.sleep( 1000 ); Collection<DatabaseQueueMessage> qmReturned = distributedQueueService.getNextMessages( queueName, 1 ); Assert.assertEquals( 1, qmReturned.size() ); DatabaseQueueMessage dqm = qmReturned.iterator().next(); DatabaseQueueMessageBody dqmb = serialization.loadMessageData( dqm.getMessageId() ); ByteBuffer blob = dqmb.getBlob(); String returnedData = new String( blob.array(), "UTF-8" ); Assert.assertEquals( data, returnedData ); distributedQueueService.shutdown(); } finally { queueManager.deleteQueue( queueName ); } }