Field<Integer> intFieldReturned = returned.getEntity().get().getField( intField.getName() );
@Test public void testDelete() throws ConnectionException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version = UUIDGenerator.newTimeUUID(); UniqueValue stored = new UniqueValueImpl( field, entityId, version ); //strategy.write( scope, stored ).execute(); BatchStatement batch = strategy.writeCQL( scope, stored, -1); session.execute(batch); //strategy.delete( scope, stored ).execute(); BatchStatement deleteBatch = strategy.deleteCQL(scope, stored); session.execute(deleteBatch); UniqueValueSet fields = strategy.load( scope, entityId.getType(), Collections.<Field>singleton( field ) ); UniqueValue nullExpected = fields.getValue( field.getName() ); Assert.assertNull( nullExpected ); Iterator<UniqueValue> allFieldsWritten = strategy.getAllUniqueFields( scope, entityId ); assertFalse("No entries left", allFieldsWritten.hasNext() ); }
entityId1.getType(), Collections.<Field>singleton( field ), true); UniqueValue retrieved = fields.getValue( field.getName() ); entityId1.getType(), Collections.<Field>singleton( field ), true); retrieved = fields.getValue( field.getName() ); entityId1.getType(), Collections.<Field>singleton( field ), true); retrieved = fields.getValue( field.getName() );
@Test public void testBasicOperation() throws ConnectionException, InterruptedException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version = UUIDGenerator.newTimeUUID(); UniqueValue stored = new UniqueValueImpl( field, entityId, version ); //strategy.write( scope, stored ).execute(); BatchStatement batch = strategy.writeCQL(scope, stored, -1); session.execute(batch); UniqueValueSet fields = strategy.load( scope, entityId.getType(), Collections.<Field>singleton( field ) ); UniqueValue retrieved = fields.getValue( field.getName() ); Assert.assertNotNull( retrieved ); assertEquals( stored, retrieved ); Iterator<UniqueValue> allFieldsWritten = strategy.getAllUniqueFields( scope, entityId ); assertTrue(allFieldsWritten.hasNext()); //test this interface. In most cases, we won't know the field name, so we want them all UniqueValue allFieldsValue = allFieldsWritten.next(); Assert.assertNotNull( allFieldsValue ); assertEquals( field, allFieldsValue.getField() ); assertEquals(version, allFieldsValue.getEntityVersion()); assertFalse(allFieldsWritten.hasNext()); }
/** * Test that inserting multiple versions of the same entity UUID result in the latest version being returned. * * @throws ConnectionException * @throws InterruptedException */ @Test public void testMultipleVersionsSameEntity() throws ConnectionException, InterruptedException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId1 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version1 = UUIDGenerator.newTimeUUID(); UUID version2 = UUIDGenerator.newTimeUUID(); UniqueValue stored1 = new UniqueValueImpl( field, entityId1, version1 ); UniqueValue stored2 = new UniqueValueImpl( field, entityId1, version2 ); session.execute(strategy.writeCQL( scope, stored1, -1 )); session.execute(strategy.writeCQL( scope, stored2, -1 )); // load descending to get the older version of entity for this unique value UniqueValueSet fields = strategy.load( scope, ConsistencyLevel.LOCAL_QUORUM, entityId1.getType(), Collections.<Field>singleton( field ), true); UniqueValue retrieved = fields.getValue( field.getName() ); Assert.assertNotNull( retrieved ); assertEquals( stored2, retrieved ); }
@Test public void testDuplicateEntitiesDescending() throws ConnectionException, InterruptedException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId1 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId2 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId3 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version1 = UUIDGenerator.newTimeUUID(); UUID version2 = UUIDGenerator.newTimeUUID(); UUID version3 = UUIDGenerator.newTimeUUID(); UniqueValue stored1 = new UniqueValueImpl( field, entityId3, version1 ); UniqueValue stored2 = new UniqueValueImpl( field, entityId2, version2 ); UniqueValue stored3 = new UniqueValueImpl( field, entityId1, version3 ); session.execute(strategy.writeCQL( scope, stored1, -1 )); session.execute(strategy.writeCQL( scope, stored2, -1 )); session.execute(strategy.writeCQL( scope, stored3, -1 )); // load descending to get the older version of entity for this unique value UniqueValueSet fields = strategy.load( scope, ConsistencyLevel.LOCAL_QUORUM, entityId1.getType(), Collections.<Field>singleton( field ), true); UniqueValue retrieved = fields.getValue( field.getName() ); assertEquals( stored3, retrieved ); }
@Test public void testDuplicateEntitiesAscending() throws ConnectionException, InterruptedException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId1 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId2 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId3 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version1 = UUIDGenerator.newTimeUUID(); UUID version2 = UUIDGenerator.newTimeUUID(); UUID version3 = UUIDGenerator.newTimeUUID(); UniqueValue stored1 = new UniqueValueImpl( field, entityId1, version1 ); UniqueValue stored2 = new UniqueValueImpl( field, entityId2, version2 ); UniqueValue stored3 = new UniqueValueImpl( field, entityId3, version3 ); session.execute(strategy.writeCQL( scope, stored1, -1 )); session.execute(strategy.writeCQL( scope, stored2, -1 )); session.execute(strategy.writeCQL( scope, stored3, -1 )); // load descending to get the older version of entity for this unique value UniqueValueSet fields = strategy.load( scope, ConsistencyLevel.LOCAL_QUORUM, entityId1.getType(), Collections.<Field>singleton( field ), true); UniqueValue retrieved = fields.getValue( field.getName() ); assertEquals( stored1, retrieved ); }
@Test public void testMixedDuplicates() throws ConnectionException, InterruptedException { ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "organization" ) ); IntegerField field = new IntegerField( "count", 5 ); Id entityId1 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId2 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); Id entityId3 = new SimpleId( UUIDGenerator.newTimeUUID(), "entity" ); UUID version1 = UUIDGenerator.newTimeUUID(); UUID version2 = UUIDGenerator.newTimeUUID(); UUID version3 = UUIDGenerator.newTimeUUID(); UUID version4 = UUIDGenerator.newTimeUUID(); UUID version5 = UUIDGenerator.newTimeUUID(); UniqueValue stored1 = new UniqueValueImpl( field, entityId1, version5 ); UniqueValue stored2 = new UniqueValueImpl( field, entityId2, version4 ); UniqueValue stored3 = new UniqueValueImpl( field, entityId1, version3 ); UniqueValue stored4 = new UniqueValueImpl( field, entityId3, version2 ); UniqueValue stored5 = new UniqueValueImpl( field, entityId3, version1 ); session.execute(strategy.writeCQL( scope, stored1, -1 )); session.execute(strategy.writeCQL( scope, stored2, -1 )); session.execute(strategy.writeCQL( scope, stored3, -1 )); session.execute(strategy.writeCQL( scope, stored4, -1 )); session.execute(strategy.writeCQL( scope, stored5, -1 )); // load descending to get the older version of entity for this unique value UniqueValueSet fields = strategy.load( scope, ConsistencyLevel.LOCAL_QUORUM, entityId1.getType(), Collections.<Field>singleton( field ), true); UniqueValue retrieved = fields.getValue( field.getName() ); assertEquals( stored1, retrieved ); }
Field<Integer> intFieldReturned = entity.getField( intField.getName() );
UniqueValue retrieved = fields.getValue( version1Field1.getName() );