You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2014/11/21 22:35:49 UTC
[11/19] incubator-usergrid git commit: Completed fix in collection
module. Renamed read methods so that it's clear we're advancing a buffer and
mutating state.
Completed fix in collection module. Renamed read methods so that it's clear we're advancing a buffer and mutating state.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/68f4e0f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/68f4e0f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/68f4e0f1
Branch: refs/heads/two-dot-o
Commit: 68f4e0f1a4942248a1f41c3c61d97fbf93440010
Parents: 262ad8b
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Nov 20 11:25:14 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Nov 20 11:25:14 2014 -0700
----------------------------------------------------------------------
.../usergrid/persistence/LargeEntityIT.java | 2 +
.../MvccEntitySerializationStrategyImpl.java | 34 +++----
.../MvccEntitySerializationStrategyV1Impl.java | 24 +++++
.../MvccEntitySerializationStrategyV2Impl.java | 95 +++++++++++++-------
.../collection/EntityCollectionManagerIT.java | 2 +-
...ccEntitySerializationSTrategyV2FixTests.java | 82 -----------------
...MvccEntitySerializationStrategyImplTest.java | 54 +++++++++++
...cEntitySerializationStrategyProxyV1Test.java | 25 ++++++
...cEntitySerializationStrategyProxyV2Test.java | 27 +++++-
...ccEntitySerializationStrategyV1ImplTest.java | 27 ++++++
...ccEntitySerializationStrategyV2ImplTest.java | 27 +++++-
.../collection/util/EntityHelper.java | 2 +-
.../core/astyanax/FieldBufferParser.java | 6 +-
.../astyanax/FieldBufferSerializerTest.java | 12 +--
14 files changed, 275 insertions(+), 144 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/core/src/test/java/org/apache/usergrid/persistence/LargeEntityIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/LargeEntityIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/LargeEntityIT.java
index ad6ca27..eef2820 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/LargeEntityIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/LargeEntityIT.java
@@ -25,6 +25,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
+import org.aspectj.lang.annotation.Before;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
@@ -47,6 +48,7 @@ public class LargeEntityIT extends AbstractCoreIT {
public Application app = new CoreApplication( setup );
+
/**
* Tests creating a large entity, then loading it, modifying it, saving it, then loading it again
*/
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
index 4138f8d..4ac5d24 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
@@ -74,20 +74,11 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS
private static final Logger log = LoggerFactory.getLogger( MvccLogEntrySerializationStrategyImpl.class );
- private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();
-
-
- private static final CollectionScopedRowKeySerializer<Id> ROW_KEY_SER =
- new CollectionScopedRowKeySerializer<Id>( ID_SER );
-
- private static final MultiTennantColumnFamily<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> CF_ENTITY_DATA =
- new MultiTennantColumnFamily<>( "Entity_Version_Data", ROW_KEY_SER, UUIDSerializer.get() );
-
-
protected final Keyspace keyspace;
protected final SerializationFig serializationFig;
protected final EntityRepair repair;
private final AbstractSerializer<EntityWrapper> entityJsonSerializer;
+ private final MultiTennantColumnFamily<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> columnFamily;
@Inject
@@ -96,6 +87,7 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS
this.serializationFig = serializationFig;
this.repair = new EntityRepairImpl( this, serializationFig );
this.entityJsonSerializer = getEntitySerializer();
+ this.columnFamily = getColumnFamily();
}
@@ -167,7 +159,7 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS
try {
- latestEntityColumns = keyspace.prepareQuery( CF_ENTITY_DATA ).getKeySlice( rowKeys )
+ latestEntityColumns = keyspace.prepareQuery( columnFamily ).getKeySlice( rowKeys )
.withColumnRange( maxVersion, null, false, 1 ).execute().getResult()
.iterator();
}
@@ -228,7 +220,7 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS
RowQuery<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> query =
- keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( rowKey )
+ keyspace.prepareQuery( columnFamily ).getKey( rowKey )
.withColumnRange( version, null, false, fetchSize );
return new ColumnNameIterator( query, new MvccColumnParser( entityId, entityJsonSerializer ), false );
@@ -258,7 +250,7 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS
RowQuery<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> query =
- keyspace.prepareQuery( CF_ENTITY_DATA ).getKey( rowKey )
+ keyspace.prepareQuery( columnFamily ).getKey( rowKey )
.withColumnRange( null, version, true, fetchSize );
return new ColumnNameIterator( query, new MvccColumnParser( entityId, entityJsonSerializer ), false );
@@ -305,7 +297,7 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS
//create the CF entity data. We want it reversed b/c we want the most recent version at the top of the
//row for fast seeks
MultiTennantColumnFamilyDefinition cf =
- new MultiTennantColumnFamilyDefinition( CF_ENTITY_DATA, BytesType.class.getSimpleName(),
+ new MultiTennantColumnFamilyDefinition( columnFamily, BytesType.class.getSimpleName(),
ReversedType.class.getSimpleName() + "(" + UUIDType.class.getSimpleName() + ")",
BytesType.class.getSimpleName(), MultiTennantColumnFamilyDefinition.CacheOption.KEYS );
@@ -332,7 +324,7 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS
ScopedRowKey.fromKey( applicationId, collectionPrefixedKey );
- op.doOp( batch.withRow( CF_ENTITY_DATA, rowKey ) );
+ op.doOp( batch.withRow( columnFamily, rowKey ) );
return batch;
}
@@ -412,4 +404,16 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS
* Return the entity serializer for this instance
*/
protected abstract AbstractSerializer<EntityWrapper> getEntitySerializer();
+
+ /**
+ * Get the column family to perform operations with
+ * @return
+ */
+ protected abstract MultiTennantColumnFamily<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> getColumnFamily();
+ /**
+ *
+ private static final MultiTennantColumnFamily<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> CF_ENTITY_DATA =
+ new MultiTennantColumnFamily<>( "Entity_Version_Data", ROW_KEY_SER, UUIDSerializer.get() );
+
+ */
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV1Impl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV1Impl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV1Impl.java
index 49b3486..b40243d 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV1Impl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV1Impl.java
@@ -21,11 +21,16 @@ package org.apache.usergrid.persistence.collection.serialization.impl;
import java.nio.ByteBuffer;
import java.util.Arrays;
+import java.util.UUID;
import org.apache.usergrid.persistence.collection.MvccEntity;
import org.apache.usergrid.persistence.collection.exception.DataCorruptionException;
import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
+import org.apache.usergrid.persistence.core.astyanax.IdRowCompositeSerializer;
+import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamily;
+import org.apache.usergrid.persistence.core.astyanax.ScopedRowKey;
import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
@@ -39,6 +44,7 @@ import com.netflix.astyanax.model.Composites;
import com.netflix.astyanax.serializers.AbstractSerializer;
import com.netflix.astyanax.serializers.ByteBufferSerializer;
import com.netflix.astyanax.serializers.BytesArraySerializer;
+import com.netflix.astyanax.serializers.UUIDSerializer;
/**
@@ -50,6 +56,18 @@ public class MvccEntitySerializationStrategyV1Impl extends MvccEntitySerializati
private static final EntitySerializer ENTITY_JSON_SER = new EntitySerializer();
+ private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();
+
+
+ private static final CollectionScopedRowKeySerializer<Id> ROW_KEY_SER =
+ new CollectionScopedRowKeySerializer<>( ID_SER );
+
+
+ private static final MultiTennantColumnFamily<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> CF_ENTITY_DATA =
+ new MultiTennantColumnFamily<>( "Entity_Version_Data", ROW_KEY_SER, UUIDSerializer.get() );
+
+
+
@Inject
public MvccEntitySerializationStrategyV1Impl( final Keyspace keyspace, final SerializationFig serializationFig ) {
super( keyspace, serializationFig );
@@ -62,6 +80,12 @@ public class MvccEntitySerializationStrategyV1Impl extends MvccEntitySerializati
}
+ @Override
+ protected MultiTennantColumnFamily<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> getColumnFamily() {
+ return CF_ENTITY_DATA;
+ }
+
+
public static class EntitySerializer extends AbstractSerializer<EntityWrapper> {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2Impl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2Impl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2Impl.java
index f80960d..723bb38 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2Impl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2Impl.java
@@ -21,12 +21,20 @@ package org.apache.usergrid.persistence.collection.serialization.impl;
import java.nio.ByteBuffer;
-import java.util.Arrays;
+import java.util.UUID;
import org.apache.usergrid.persistence.collection.MvccEntity;
import org.apache.usergrid.persistence.collection.exception.DataCorruptionException;
import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
+import org.apache.usergrid.persistence.core.astyanax.FieldBuffer;
+import org.apache.usergrid.persistence.core.astyanax.FieldBufferBuilder;
+import org.apache.usergrid.persistence.core.astyanax.FieldBufferParser;
+import org.apache.usergrid.persistence.core.astyanax.FieldBufferSerializer;
+import org.apache.usergrid.persistence.core.astyanax.IdRowCompositeSerializer;
+import org.apache.usergrid.persistence.core.astyanax.MultiTennantColumnFamily;
+import org.apache.usergrid.persistence.core.astyanax.ScopedRowKey;
import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
@@ -34,12 +42,8 @@ import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.netflix.astyanax.Keyspace;
-import com.netflix.astyanax.model.CompositeBuilder;
-import com.netflix.astyanax.model.CompositeParser;
-import com.netflix.astyanax.model.Composites;
import com.netflix.astyanax.serializers.AbstractSerializer;
-import com.netflix.astyanax.serializers.ByteBufferSerializer;
-import com.netflix.astyanax.serializers.BytesArraySerializer;
+import com.netflix.astyanax.serializers.UUIDSerializer;
/**
@@ -51,6 +55,20 @@ public class MvccEntitySerializationStrategyV2Impl extends MvccEntitySerializati
private static final EntitySerializer ENTITY_JSON_SER = new EntitySerializer();
+ private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();
+
+
+ private static final CollectionScopedRowKeySerializer<Id> ROW_KEY_SER =
+ new CollectionScopedRowKeySerializer<>( ID_SER );
+
+
+ private static final MultiTennantColumnFamily<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> CF_ENTITY_DATA =
+ new MultiTennantColumnFamily<>( "Entity_Version_Data_V2", ROW_KEY_SER, UUIDSerializer.get() );
+
+ private static final FieldBufferSerializer FIELD_BUFFER_SERIALIZER = FieldBufferSerializer.get();
+
+
+
@Inject
public MvccEntitySerializationStrategyV2Impl( final Keyspace keyspace, final SerializationFig serializationFig ) {
super( keyspace, serializationFig );
@@ -63,23 +81,29 @@ public class MvccEntitySerializationStrategyV2Impl extends MvccEntitySerializati
}
- public static class EntitySerializer extends AbstractSerializer<EntityWrapper> {
+ @Override
+ protected MultiTennantColumnFamily<ScopedRowKey<CollectionPrefixedKey<Id>>, UUID> getColumnFamily() {
+ return CF_ENTITY_DATA;
+ }
+
+ public static class EntitySerializer extends AbstractSerializer<EntityWrapper> {
- private static final ByteBufferSerializer BUFFER_SERIALIZER = ByteBufferSerializer.get();
- private static final BytesArraySerializer BYTES_ARRAY_SERIALIZER = BytesArraySerializer.get();
+// private static final ByteBufferSerializer BUFFER_SERIALIZER = ByteBufferSerializer.get();
+//
+// private static final BytesArraySerializer BYTES_ARRAY_SERIALIZER = BytesArraySerializer.get();
public static final SmileFactory f = new SmileFactory();
public static ObjectMapper mapper;
- private static byte[] STATE_COMPLETE = new byte[] { 0 };
- private static byte[] STATE_DELETED = new byte[] { 1 };
- private static byte[] STATE_PARTIAL = new byte[] { 2 };
+ private static byte STATE_COMPLETE = 0 ;
+ private static byte STATE_DELETED = 1 ;
+ private static byte STATE_PARTIAL = 2 ;
- private static byte[] VERSION = new byte[] { 0 };
+ private static byte VERSION = 1;
public EntitySerializer() {
@@ -101,26 +125,28 @@ public class MvccEntitySerializationStrategyV2Impl extends MvccEntitySerializati
return null;
}
- CompositeBuilder builder = Composites.newCompositeBuilder();
+ //we always have a max of 3 fields
+ FieldBufferBuilder builder = new FieldBufferBuilder( 3 );
- builder.addBytes( VERSION );
+ builder.addByte( VERSION );
//mark this version as empty
if ( !wrapper.entity.isPresent() ) {
//we're empty
- builder.addBytes( STATE_DELETED );
+ builder.addByte( STATE_DELETED );
- return builder.build();
+
+ return FIELD_BUFFER_SERIALIZER.toByteBuffer( builder.build() );
}
//we have an entity
if ( wrapper.status == MvccEntity.Status.COMPLETE ) {
- builder.addBytes( STATE_COMPLETE );
+ builder.addByte( STATE_COMPLETE );
}
else {
- builder.addBytes( STATE_PARTIAL );
+ builder.addByte( STATE_PARTIAL );
}
try {
@@ -131,7 +157,7 @@ public class MvccEntitySerializationStrategyV2Impl extends MvccEntitySerializati
throw new RuntimeException( "Unable to serialize entity", e );
}
- return builder.build();
+ return FIELD_BUFFER_SERIALIZER.toByteBuffer( builder.build() );
}
@@ -141,41 +167,44 @@ public class MvccEntitySerializationStrategyV2Impl extends MvccEntitySerializati
/**
* We intentionally turn data corruption exceptions when we're unable to de-serialize
* the data in cassandra. If this occurs, we'll never be able to de-serialize it
- * and it should be considered lost. This is an error that is occuring due to a bug
+ * and it should be considered lost. This is an error that is occurring due to a bug
* in serializing the entity. This is a lazy recognition + repair signal for deployment with
* existing systems.
*/
- CompositeParser parser;
+
+ final FieldBuffer fieldBuffer;
+
try {
- parser = Composites.newCompositeParser( byteBuffer );
+ fieldBuffer = FIELD_BUFFER_SERIALIZER.fromByteBuffer( byteBuffer );
}
catch ( Exception e ) {
throw new DataCorruptionException( "Unable to de-serialze entity", e );
}
- byte[] version = parser.read( BYTES_ARRAY_SERIALIZER );
+ FieldBufferParser parser = new FieldBufferParser( fieldBuffer );
+
+
+
+ byte version = parser.readByte();
- if ( !Arrays.equals( VERSION, version ) ) {
+ if ( VERSION != version ) {
throw new UnsupportedOperationException( "A version of type " + version + " is unsupported" );
}
- byte[] state = parser.read( BYTES_ARRAY_SERIALIZER );
+ byte state = parser.readByte();
// it's been deleted, remove it
- if ( Arrays.equals( STATE_DELETED, state ) ) {
+ if ( STATE_DELETED == state ) {
return new EntityWrapper( MvccEntity.Status.COMPLETE, Optional.<Entity>absent() );
}
Entity storedEntity;
- ByteBuffer jsonBytes = parser.read( BUFFER_SERIALIZER );
- byte[] array = jsonBytes.array();
- int start = jsonBytes.arrayOffset();
- int length = jsonBytes.remaining();
+ byte[] array = parser.readBytes();
try {
- storedEntity = mapper.readValue( array, start, length, Entity.class );
+ storedEntity = mapper.readValue( array, Entity.class );
}
catch ( Exception e ) {
throw new DataCorruptionException( "Unable to read entity data", e );
@@ -183,7 +212,7 @@ public class MvccEntitySerializationStrategyV2Impl extends MvccEntitySerializati
final Optional<Entity> entity = Optional.of( storedEntity );
- if ( Arrays.equals( STATE_COMPLETE, state ) ) {
+ if ( STATE_COMPLETE == state ) {
return new EntityWrapper( MvccEntity.Status.COMPLETE, entity );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index db5e3a4..21e3260 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -731,6 +731,6 @@ public class EntityCollectionManagerIT {
final Entity loaded = manager.load( entity.getId() ).toBlocking().last();
- EntityHelper.verifySame( entity, loaded );
+ EntityHelper.verifyDeepEquals( entity, loaded );
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationSTrategyV2FixTests.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationSTrategyV2FixTests.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationSTrategyV2FixTests.java
deleted file mode 100644
index 0d7e335..0000000
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationSTrategyV2FixTests.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.usergrid.persistence.collection.serialization.impl;
-
-
-import java.util.Iterator;
-import java.util.UUID;
-
-import org.junit.Test;
-
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.MvccEntity;
-import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
-import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityImpl;
-import org.apache.usergrid.persistence.collection.util.EntityHelper;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-
-public abstract class MvccEntitySerializationSTrategyV2FixTests extends MvccEntitySerializationStrategyImplTest {
-
-
- /**
- * Tests an entity with more than 65535 bytes worth of data is successfully stored and retrieved
- */
- @Test
- public void largeEntityWriteRead() throws ConnectionException {
- final int setSize = 65535 * 2;
-
- final Entity entity = EntityHelper.generateEntity( setSize );
-
- //now we have one massive, entity, save it and retrieve it.
- CollectionScope context =
- new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
-
-
- final Id simpleId = new SimpleId( "test" );
- final UUID version = UUIDGenerator.newTimeUUID();
- final MvccEntity.Status status = MvccEntity.Status.COMPLETE;
-
- final MvccEntity mvccEntity = new MvccEntityImpl( simpleId, version, status, entity );
-
-
- getMvccEntitySerializationStrategy().write( context, mvccEntity ).execute();
-
- //now load it
- final Iterator<MvccEntity> loaded =
- getMvccEntitySerializationStrategy().loadAscendingHistory( context, entity.getId(), version, 100 );
-
- assertTrue( loaded.hasNext() );
-
- final MvccEntity loadedEntity = loaded.next();
-
- assertEquals( "The loaded entity should match the stored entity", mvccEntity, loadedEntity );
-
- EntityHelper.verifySame( entity, loadedEntity.getEntity().get() );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
index d54d958..0cdc320 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
@@ -35,9 +35,11 @@ import org.apache.usergrid.persistence.collection.MvccEntity;
import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityImpl;
+import org.apache.usergrid.persistence.collection.util.EntityHelper;
import org.apache.usergrid.persistence.collection.util.EntityUtils;
import org.apache.usergrid.persistence.core.astyanax.CassandraFig;
import org.apache.usergrid.persistence.core.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.core.util.ValidationUtils;
import org.apache.usergrid.persistence.model.entity.Entity;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;
@@ -579,6 +581,58 @@ public abstract class MvccEntitySerializationStrategyImplTest {
}
+
+ /**
+ * Tests an entity with more than 65535 bytes worth of data is successfully stored and retrieved
+ */
+ @Test
+ public void largeEntityWriteRead() throws ConnectionException {
+ final int setSize = 65535 * 2;
+
+ final Entity entity = EntityHelper.generateEntity( setSize );
+
+ //now we have one massive, entity, save it and retrieve it.
+ CollectionScope context =
+ new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "parent" ), "tests" );
+
+
+ final Id id = entity.getId();
+ ValidationUtils.verifyIdentity( id );
+ final UUID version = UUIDGenerator.newTimeUUID();
+ final MvccEntity.Status status = MvccEntity.Status.COMPLETE;
+
+ final MvccEntity mvccEntity = new MvccEntityImpl( id, version, status, entity );
+
+
+ getMvccEntitySerializationStrategy().write( context, mvccEntity ).execute();
+
+ //now load it
+ final Iterator<MvccEntity> loaded =
+ getMvccEntitySerializationStrategy().loadDescendingHistory( context, id, version, 100 );
+
+
+ assertLargeEntity( mvccEntity, loaded );
+
+ MvccEntity returned = serializationStrategy.load( context, Collections.singleton( id ) , version ).getEntity( id );
+
+ assertLargeEntity( mvccEntity, returned );
+ }
+
+
+ /**
+ * Assertion for the loaded values of a large entity. Note the returned may be nullable
+ * @param expected
+ * @param returned
+ */
+ protected abstract void assertLargeEntity(final MvccEntity expected, final Iterator<MvccEntity> returned);
+
+ /**
+ * Tests large entity that is directly returned
+ * @param expected
+ * @param returned
+ */
+ protected abstract void assertLargeEntity(final MvccEntity expected, final MvccEntity returned);
+
@Test(expected = NullPointerException.class)
public void writeParamsContext() throws ConnectionException {
serializationStrategy.write( null, mock( MvccEntity.class ) );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyV1Test.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyV1Test.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyV1Test.java
index 331bea2..df5f7d1 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyV1Test.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyV1Test.java
@@ -20,10 +20,13 @@
package org.apache.usergrid.persistence.collection.serialization.impl;
+import java.util.Iterator;
+
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
+import org.apache.usergrid.persistence.collection.MvccEntity;
import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
import org.apache.usergrid.persistence.core.guice.PreviousImpl;
@@ -34,6 +37,9 @@ import org.apache.usergrid.persistence.core.test.UseModules;
import com.google.inject.Inject;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -69,6 +75,25 @@ public class MvccEntitySerializationStrategyProxyV1Test extends MvccEntitySerial
}
+
+ @Override
+ protected void assertLargeEntity( final MvccEntity expected, final Iterator<MvccEntity> returned ) {
+ //known bug in v1, it should return null. Fixed in v2
+ assertTrue( "V1 should be broken, but still have a next", returned.hasNext() );
+
+ final MvccEntity entity = returned.next();
+
+
+ assertLargeEntity( expected, entity );
+ }
+
+
+ protected void assertLargeEntity( final MvccEntity expected, final MvccEntity returned ) {
+ assertEquals( "Marked as deleted since we can't parse", MvccEntity.Status.DELETED, returned.getStatus() );
+
+ assertFalse( "V1 returns empty b/c parse fails", returned.getEntity().isPresent() );
+ }
+
@After
public void reSetMigrationVersion() {
migrationInfoSerialization.setVersion( existingVersion );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyV2Test.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyV2Test.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyV2Test.java
index 02eccb1..dc31ff7 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyV2Test.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyProxyV2Test.java
@@ -20,12 +20,16 @@
package org.apache.usergrid.persistence.collection.serialization.impl;
+import java.util.Iterator;
+
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
+import org.apache.usergrid.persistence.collection.MvccEntity;
import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
+import org.apache.usergrid.persistence.collection.util.EntityHelper;
import org.apache.usergrid.persistence.core.guice.ProxyImpl;
import org.apache.usergrid.persistence.core.migration.data.MigrationInfoSerialization;
import org.apache.usergrid.persistence.core.test.ITRunner;
@@ -33,10 +37,12 @@ import org.apache.usergrid.persistence.core.test.UseModules;
import com.google.inject.Inject;
+import static org.junit.Assert.assertTrue;
+
@RunWith( ITRunner.class )
@UseModules( TestCollectionModule.class )
-public class MvccEntitySerializationStrategyProxyV2Test extends MvccEntitySerializationSTrategyV2FixTests {
+public class MvccEntitySerializationStrategyProxyV2Test extends MvccEntitySerializationStrategyImplTest {
@Inject
@ProxyImpl
@@ -68,6 +74,25 @@ public class MvccEntitySerializationStrategyProxyV2Test extends MvccEntitySerial
}
+ @Override
+ protected void assertLargeEntity( final MvccEntity expected, final Iterator<MvccEntity> returned ) {
+ assertTrue( returned.hasNext() );
+
+ final MvccEntity loadedEntity = returned.next();
+
+ assertLargeEntity( expected, loadedEntity );
+ }
+
+
+ @Override
+ protected void assertLargeEntity( final MvccEntity expected, final MvccEntity returned ) {
+
+ org.junit.Assert.assertEquals( "The loaded entity should match the stored entity", expected, returned );
+
+ EntityHelper.verifyDeepEquals( expected.getEntity().get(), returned.getEntity().get() );
+ }
+
+
@After
public void reSetMigrationVersion() {
migrationInfoSerialization.setVersion( existingVersion );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV1ImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV1ImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV1ImplTest.java
index 01d9a9b..9b0ccfb 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV1ImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV1ImplTest.java
@@ -20,8 +20,11 @@
package org.apache.usergrid.persistence.collection.serialization.impl;
+import java.util.Iterator;
+
import org.junit.runner.RunWith;
+import org.apache.usergrid.persistence.collection.MvccEntity;
import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
import org.apache.usergrid.persistence.core.guice.PreviousImpl;
@@ -30,6 +33,10 @@ import org.apache.usergrid.persistence.core.test.UseModules;
import com.google.inject.Inject;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
@RunWith( ITRunner.class )
@UseModules( TestCollectionModule.class )
@@ -39,6 +46,26 @@ public class MvccEntitySerializationStrategyV1ImplTest extends MvccEntitySeriali
@PreviousImpl
private MvccEntitySerializationStrategy serializationStrategy;
+
+ @Override
+ protected void assertLargeEntity( final MvccEntity expected, final Iterator<MvccEntity> returned ) {
+ //known bug in v1, it should return null. Fixed in v2
+ assertTrue( "V1 should be broken, but still have a next", returned.hasNext() );
+
+ final MvccEntity entity = returned.next();
+
+
+ assertLargeEntity( expected, entity );
+ }
+
+
+ protected void assertLargeEntity( final MvccEntity expected, final MvccEntity returned ) {
+ assertEquals( "Marked as deleted since we can't parse", MvccEntity.Status.DELETED, returned.getStatus() );
+
+ assertFalse( "V1 returns empty b/c parse fails", returned.getEntity().isPresent() );
+ }
+
+
@Override
protected MvccEntitySerializationStrategy getMvccEntitySerializationStrategy() {
return serializationStrategy;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2ImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2ImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2ImplTest.java
index 012eeff..53952d0 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2ImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2ImplTest.java
@@ -20,30 +20,53 @@
package org.apache.usergrid.persistence.collection.serialization.impl;
+import java.util.Iterator;
+
import org.junit.runner.RunWith;
+import org.apache.usergrid.persistence.collection.MvccEntity;
import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
+import org.apache.usergrid.persistence.collection.util.EntityHelper;
import org.apache.usergrid.persistence.core.guice.CurrentImpl;
-import org.apache.usergrid.persistence.core.guice.PreviousImpl;
import org.apache.usergrid.persistence.core.test.ITRunner;
import org.apache.usergrid.persistence.core.test.UseModules;
import com.google.inject.Inject;
+import static org.junit.Assert.assertTrue;
+
@RunWith( ITRunner.class )
@UseModules( TestCollectionModule.class )
-public class MvccEntitySerializationStrategyV2ImplTest extends MvccEntitySerializationSTrategyV2FixTests {
+public class MvccEntitySerializationStrategyV2ImplTest extends MvccEntitySerializationStrategyImplTest {
@Inject
@CurrentImpl
private MvccEntitySerializationStrategy serializationStrategy;
+
@Override
protected MvccEntitySerializationStrategy getMvccEntitySerializationStrategy() {
return serializationStrategy;
}
+ @Override
+ protected void assertLargeEntity( final MvccEntity expected, final Iterator<MvccEntity> returned ) {
+ assertTrue( returned.hasNext() );
+
+ final MvccEntity loadedEntity = returned.next();
+
+ assertLargeEntity( expected, loadedEntity );
+ }
+
+
+ @Override
+ protected void assertLargeEntity( final MvccEntity expected, final MvccEntity returned ) {
+
+ org.junit.Assert.assertEquals( "The loaded entity should match the stored entity", expected, returned );
+
+ EntityHelper.verifyDeepEquals( expected.getEntity().get(), returned.getEntity().get() );
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/util/EntityHelper.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/util/EntityHelper.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/util/EntityHelper.java
index 4eb09ab..5c99121 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/util/EntityHelper.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/util/EntityHelper.java
@@ -81,7 +81,7 @@ public class EntityHelper {
* @param expected
* @param returned
*/
- public static void verifySame(final Entity expected, final Entity returned){
+ public static void verifyDeepEquals( final Entity expected, final Entity returned ){
//perform object equals
assertEquals("Expected same entity equality", expected, returned);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/FieldBufferParser.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/FieldBufferParser.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/FieldBufferParser.java
index ef3b962..68bb32b 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/FieldBufferParser.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/FieldBufferParser.java
@@ -50,7 +50,7 @@ public class FieldBufferParser {
/**
* Return the value as an integer
*/
- public int getInteger() {
+ public int readInteger() {
return INTEGER_SERIALIZER.fromByteBuffer( getNext() );
}
@@ -58,7 +58,7 @@ public class FieldBufferParser {
/**
* Return the value as a byte array
*/
- public byte[] getBytes() {
+ public byte[] readBytes() {
return BYTES_ARRAY_SERIALIZER.fromByteBuffer( getNext() );
}
@@ -66,7 +66,7 @@ public class FieldBufferParser {
/**
* return the next vlaue as a byte
*/
- public byte getByte() {
+ public byte readByte() {
return BYTE_SERIALIZER.fromByteBuffer( getNext() );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68f4e0f1/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/FieldBufferSerializerTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/FieldBufferSerializerTest.java b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/FieldBufferSerializerTest.java
index e9a8194..850bcdd 100644
--- a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/FieldBufferSerializerTest.java
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/astyanax/FieldBufferSerializerTest.java
@@ -60,15 +60,15 @@ public class FieldBufferSerializerTest {
FieldBufferParser parser = new FieldBufferParser( parsed );
- final byte returnedByte = parser.getByte();
+ final byte returnedByte = parser.readByte();
assertEquals( "Bytes should be equal", setByte, returnedByte );
- final int returnedInt = parser.getInteger();
+ final int returnedInt = parser.readInteger();
assertEquals( "Integer should be equal", setInteger, returnedInt );
- final byte[] returnedByteArray = parser.getBytes();
+ final byte[] returnedByteArray = parser.readBytes();
assertArrayEquals( "arrays should be equal", setByteArray, returnedByteArray );
}
@@ -101,15 +101,15 @@ public class FieldBufferSerializerTest {
FieldBufferParser parser = new FieldBufferParser( parsed );
- final byte[] returnedArray = parser.getBytes();
+ final byte[] returnedArray = parser.readBytes();
assertArrayEquals( setByteArray, returnedArray );
- final byte returnedByte = parser.getByte();
+ final byte returnedByte = parser.readByte();
assertEquals( "Bytes should be equal", setByte, returnedByte );
- final int returnedInt = parser.getInteger();
+ final int returnedInt = parser.readInteger();
assertEquals( "Integer should be equal", setInteger, returnedInt );
}