You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2016/05/02 23:42:27 UTC
[15/18] usergrid git commit: Fixes to get all JUnit tests working
again.
Fixes to get all JUnit tests working again.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/02c17959
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/02c17959
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/02c17959
Branch: refs/heads/usergrid-1268-akka-211
Commit: 02c179594d067b69c8e10c0babc48c5460501e7a
Parents: 3e7aac2
Author: Dave Johnson <sn...@apache.org>
Authored: Tue Apr 26 10:32:05 2016 -0400
Committer: Dave Johnson <sn...@apache.org>
Committed: Tue Apr 26 10:32:05 2016 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityManagerFactory.java | 1 +
.../collection/EntityCollectionManager.java | 6 +-
.../EntityCollectionManagerFactory.java | 4 +-
.../EntityCollectionManagerFactoryImpl.java | 57 ++++++++++-------
.../impl/EntityCollectionManagerImpl.java | 38 +++++++++--
.../mvcc/stage/write/WriteCommit.java | 27 --------
.../uniquevalues/UniqueValuesServiceImpl.java | 9 +++
.../collection/EntityCollectionManagerIT.java | 67 +++++++++++---------
.../mvcc/stage/write/WriteUniqueVerifyIT.java | 22 ++++++-
.../mvcc/stage/write/WriteUniqueVerifyTest.java | 23 ++++++-
.../apache/usergrid/rest/UniqueValuesIT.java | 15 ++++-
.../collection/CollectionsResourceIT.java | 41 ------------
12 files changed, 170 insertions(+), 140 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index e6acf2e..c197376 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -157,6 +157,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
this.uniqueValuesService.start();
} catch (Throwable t) {
logger.error("Error starting Akka", t);
+ throw t;
}
}
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
index 0fc5636..847341b 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
@@ -113,10 +113,14 @@ public interface EntityCollectionManager {
*/
Observable<MvccLogEntry> delete( final Collection<MvccLogEntry> entries );
-
/**
* Returns health of entity data store.
*/
Health getHealth();
+ /**
+ * For testing purposes only.
+ */
+ void startAkkaForTesting( String hostname, int port, String region );
+
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerFactory.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerFactory.java
index 1d6f45e..d93ac20 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerFactory.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerFactory.java
@@ -39,9 +39,7 @@ public interface EntityCollectionManagerFactory {
*
* @return The EntityCollectionManager to perform operations within the applicationscope provided
*/
- EntityCollectionManager
- createCollectionManager( ApplicationScope applicationScope );
-
+ EntityCollectionManager createCollectionManager( ApplicationScope applicationScope );
void invalidate();
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerFactoryImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerFactoryImpl.java
index 6ba23b6..18a07ac 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerFactoryImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerFactoryImpl.java
@@ -1,21 +1,19 @@
/*
-<<<<<<< HEAD
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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
*
- * * Licensed to the Apache Software Foundation (ASF) under one or more
- * * contributor license agreements. 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. For additional information regarding
- * * copyright in this work, please see the NOTICE file in the top level
- * * directory of this distribution.
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
*
*/
package org.apache.usergrid.persistence.collection.impl;
@@ -40,6 +38,7 @@ import org.apache.usergrid.persistence.collection.serialization.MvccEntitySerial
import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.collection.uniquevalues.UniqueValuesService;
import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
import org.apache.usergrid.persistence.core.rx.RxTaskScheduler;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
@@ -77,6 +76,8 @@ public class EntityCollectionManagerFactoryImpl implements EntityCollectionManag
private final Keyspace keyspace;
private final MetricsFactory metricsFactory;
private final RxTaskScheduler rxTaskScheduler;
+ private final UniqueValuesService uniqueValuesService;
+
private LoadingCache<ApplicationScope, EntityCollectionManager> ecmCache =
CacheBuilder.newBuilder().maximumSize( 1000 )
@@ -100,6 +101,7 @@ public class EntityCollectionManagerFactoryImpl implements EntityCollectionManag
metricsFactory,
serializationFig,
rxTaskScheduler,
+ uniqueValuesService,
scope );
return target;
@@ -109,18 +111,24 @@ public class EntityCollectionManagerFactoryImpl implements EntityCollectionManag
@Inject
public EntityCollectionManagerFactoryImpl(
- final WriteStart writeStart, final WriteUniqueVerify writeVerifyUnique,
+ final WriteStart writeStart,
+ final WriteUniqueVerify writeVerifyUnique,
final WriteOptimisticVerify writeOptimisticVerify,
- final WriteCommit writeCommit, final RollbackAction rollback,
- final MarkStart markStart, final MarkCommit markCommit,
- final UniqueCleanup uniqueCleanup, final VersionCompact versionCompact,
+ final WriteCommit writeCommit,
+ final RollbackAction rollback,
+ final MarkStart markStart,
+ final MarkCommit markCommit,
+ final UniqueCleanup uniqueCleanup,
+ final VersionCompact versionCompact,
final SerializationFig serializationFig,
final MvccEntitySerializationStrategy entitySerializationStrategy,
final UniqueValueSerializationStrategy uniqueValueSerializationStrategy,
final MvccLogEntrySerializationStrategy mvccLogEntrySerializationStrategy,
- final Keyspace keyspace, final EntityCacheFig entityCacheFig,
+ final Keyspace keyspace,
+ final EntityCacheFig entityCacheFig,
final MetricsFactory metricsFactory, @CollectionExecutorScheduler
- final RxTaskScheduler rxTaskScheduler ) {
+ final RxTaskScheduler rxTaskScheduler,
+ final UniqueValuesService uniqueValuesService ) {
this.writeStart = writeStart;
this.writeVerifyUnique = writeVerifyUnique;
@@ -138,14 +146,15 @@ public class EntityCollectionManagerFactoryImpl implements EntityCollectionManag
this.keyspace = keyspace;
this.metricsFactory = metricsFactory;
this.rxTaskScheduler = rxTaskScheduler;
+ this.uniqueValuesService = uniqueValuesService;
}
@Override
public EntityCollectionManager createCollectionManager(ApplicationScope applicationScope) {
Preconditions.checkNotNull(applicationScope);
- try{
+ try {
return ecmCache.get(applicationScope);
- }catch (ExecutionException ee){
+ } catch (ExecutionException ee) {
throw new RuntimeException(ee);
}
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index b7ea865..544e7bb 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.UUID;
import com.netflix.astyanax.model.ConsistencyLevel;
+import org.apache.usergrid.persistence.collection.uniquevalues.UniqueValuesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -122,19 +123,29 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
private final ApplicationScope applicationScope;
private final RxTaskScheduler rxTaskScheduler;
+ private final UniqueValuesService uniqueValuesService;
+
@Inject
- public EntityCollectionManagerImpl( final WriteStart writeStart, final WriteUniqueVerify writeVerifyUnique,
+ public EntityCollectionManagerImpl( final WriteStart writeStart,
+ final WriteUniqueVerify writeVerifyUnique,
final WriteOptimisticVerify writeOptimisticVerify,
- final WriteCommit writeCommit, final RollbackAction rollback,
- final MarkStart markStart, final MarkCommit markCommit,
- final UniqueCleanup uniqueCleanup, final VersionCompact versionCompact,
+ final WriteCommit writeCommit,
+ final RollbackAction rollback,
+ final MarkStart markStart,
+ final MarkCommit markCommit,
+ final UniqueCleanup uniqueCleanup,
+ final VersionCompact versionCompact,
final MvccEntitySerializationStrategy entitySerializationStrategy,
final UniqueValueSerializationStrategy uniqueValueSerializationStrategy,
final MvccLogEntrySerializationStrategy mvccLogEntrySerializationStrategy,
- final Keyspace keyspace, final MetricsFactory metricsFactory,
- final SerializationFig serializationFig, final RxTaskScheduler rxTaskScheduler,
+ final Keyspace keyspace,
+ final MetricsFactory metricsFactory,
+ final SerializationFig serializationFig,
+ final RxTaskScheduler rxTaskScheduler,
+ UniqueValuesService uniqueValuesService,
@Assisted final ApplicationScope applicationScope ) {
+
this.uniqueValueSerializationStrategy = uniqueValueSerializationStrategy;
this.entitySerializationStrategy = entitySerializationStrategy;
this.uniqueCleanup = uniqueCleanup;
@@ -142,6 +153,8 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
this.serializationFig = serializationFig;
this.rxTaskScheduler = rxTaskScheduler;
+ this.uniqueValuesService = uniqueValuesService;
+
ValidationUtils.validateApplicationScope( applicationScope );
this.writeStart = writeStart;
@@ -459,4 +472,17 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
return Health.RED;
}
+
+
+ @Override
+ public void startAkkaForTesting( String hostname, int port, String region ) {
+ try {
+ uniqueValuesService.start( hostname, port, region );
+ uniqueValuesService.waitForRequestActors();
+
+ } catch (Throwable t) {
+ logger.error("Error starting Akka", t);
+ throw t;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
index 7556911..abb54c9 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
@@ -98,36 +98,9 @@ public class WriteCommit implements Func1<CollectionIoEvent<MvccEntity>, Collect
@Override
public CollectionIoEvent<MvccEntity> call( final CollectionIoEvent<MvccEntity> ioEvent ) {
- if ( akkaFig.getAkkaEnabled() ) {
- return confirmUniqueFieldsAkka( ioEvent );
- }
return confirmUniqueFields( ioEvent );
}
- private CollectionIoEvent<MvccEntity> confirmUniqueFieldsAkka(CollectionIoEvent<MvccEntity> ioEvent) {
-
- final MvccEntity mvccEntity = ioEvent.getEvent();
- MvccValidationUtils.verifyMvccEntityWithEntity( mvccEntity );
-
- final Id entityId = mvccEntity.getId();
- final UUID version = mvccEntity.getVersion();
- final ApplicationScope applicationScope = ioEvent.getEntityCollection();
-
- //set the version into the entity
- final Entity entity = mvccEntity.getEntity().get();
-
- try {
- akkaUvService.confirmUniqueValues(
- applicationScope, entity, mvccEntity.getVersion(), ioEvent.getRegion() );
-
- } catch (UniqueValueException e) {
- Map<String, Field> violations = new HashMap<>();
- violations.put( e.getField().getName(), e.getField() );
- throw new WriteUniqueVerifyException( mvccEntity, applicationScope, violations );
- }
-
- return ioEvent;
- }
private CollectionIoEvent<MvccEntity> confirmUniqueFields(CollectionIoEvent<MvccEntity> ioEvent) {
final MvccEntity mvccEntity = ioEvent.getEvent();
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/uniquevalues/UniqueValuesServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/uniquevalues/UniqueValuesServiceImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/uniquevalues/UniqueValuesServiceImpl.java
index ce7af76..4d7f505 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/uniquevalues/UniqueValuesServiceImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/uniquevalues/UniqueValuesServiceImpl.java
@@ -35,6 +35,7 @@ import com.google.inject.Singleton;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.apache.commons.lang3.StringUtils;
+import org.apache.usergrid.persistence.collection.exception.CollectionRuntimeException;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.model.entity.Entity;
import org.apache.usergrid.persistence.model.field.Field;
@@ -434,6 +435,10 @@ public class UniqueValuesServiceImpl implements UniqueValuesService {
public void reserveUniqueValues(
ApplicationScope scope, Entity entity, UUID version, String region ) throws UniqueValueException {
+ if ( this.getRequestActorsByRegion().isEmpty() ) {
+ throw new RuntimeException("Unique values service not initialized, no request actors ready");
+ }
+
try {
for (Field field : entity.getFields()) {
if (field.isUnique()) {
@@ -460,6 +465,10 @@ public class UniqueValuesServiceImpl implements UniqueValuesService {
public void confirmUniqueValues(
ApplicationScope scope, Entity entity, UUID version, String region ) throws UniqueValueException {
+ if ( this.getRequestActorsByRegion().isEmpty() ) {
+ throw new RuntimeException("Unique values service not initialized, no request actors ready");
+ }
+
try {
for (Field field : entity.getFields()) {
if (field.isUnique()) {
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/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 74f7038..14565c2 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
@@ -18,15 +18,9 @@
package org.apache.usergrid.persistence.collection;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.UUID;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
+import com.fasterxml.uuid.UUIDComparator;
+import com.google.inject.Inject;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import org.apache.usergrid.persistence.collection.exception.WriteUniqueVerifyException;
import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
@@ -49,20 +43,19 @@ import org.apache.usergrid.persistence.model.field.BooleanField;
import org.apache.usergrid.persistence.model.field.Field;
import org.apache.usergrid.persistence.model.field.IntegerField;
import org.apache.usergrid.persistence.model.field.StringField;
-
-import com.fasterxml.uuid.UUIDComparator;
-import com.google.inject.Inject;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import rx.Observable;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.junit.Assert.*;
/** @author tnine */
@@ -87,14 +80,23 @@ public class EntityCollectionManagerIT {
@Inject
private MvccEntitySerializationStrategy entitySerializationStrategy;
+ private static AtomicBoolean startedAkka = new AtomicBoolean( false );
+
+ @Before
+ public void initAkka() {
+ if ( !startedAkka.getAndSet( true ) ) {
+ ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) );
+ EntityCollectionManager manager = factory.createCollectionManager( context );
+ manager.startAkkaForTesting( "127.0.0.1", 2551, "us-east" );
+ }
+ }
+
@Test
public void write() {
-
ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) );
-
Entity newEntity = new Entity( new SimpleId( "test" ) );
EntityCollectionManager manager = factory.createCollectionManager( context );
@@ -112,7 +114,6 @@ public class EntityCollectionManagerIT {
@Test
public void writeWithUniqueValues() {
-
ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) );
EntityCollectionManager manager = factory.createCollectionManager( context );
@@ -288,7 +289,6 @@ public class EntityCollectionManagerIT {
@Test
public void writeAndGetField() {
-
ApplicationScope collectionScope1 = new ApplicationScopeImpl( new SimpleId( "organization" ) );
Entity newEntity = new Entity( new SimpleId( "test" ) );
@@ -317,6 +317,7 @@ public class EntityCollectionManagerIT {
@Test
public void writeAndGetField2X() throws InterruptedException {
+
ApplicationScope collectionScope1 = new ApplicationScopeImpl( new SimpleId( "organization" ) );
final Id entityId = new SimpleId( "test" );
@@ -334,12 +335,14 @@ public class EntityCollectionManagerIT {
assertNotNull( "Id was assigned", createReturned.getId() );
assertNotNull( "Version was assigned", createReturned.getVersion() );
- final Id existingId = manager.getIdField( firstInstance.getId().getType(), firstField ).toBlocking().lastOrDefault( null );
+ final Id existingId = manager.getIdField( firstInstance.getId().getType(), firstField )
+ .toBlocking().lastOrDefault( null );
assertNotNull( existingId );
assertEquals( firstInstance.getId(), existingId );
Field fieldNull = new StringField( "testFieldNotThere", "uniquely", true );
- final Id noId = manager.getIdField( firstInstance.getId().getType(), fieldNull ).toBlocking().lastOrDefault( null );
+ final Id noId = manager.getIdField( firstInstance.getId().getType(), fieldNull )
+ .toBlocking().lastOrDefault( null );
assertNull( noId );
@@ -357,7 +360,8 @@ public class EntityCollectionManagerIT {
assertNotNull( "Id was assigned", createReturnedSecond.getId() );
assertNotNull( "Version was assigned", createReturnedSecond.getVersion() );
- assertNotEquals( "Versions should not be equal", createReturned.getVersion(), createReturnedSecond.getVersion() );
+ assertNotEquals( "Versions should not be equal",
+ createReturned.getVersion(), createReturnedSecond.getVersion() );
//sanity check, get the entity to ensure it's the right version
@@ -370,11 +374,13 @@ public class EntityCollectionManagerIT {
Thread.sleep( 2000 );
//TODO, we need to implement verify and repair on this
- final Id idFirst = manager.getIdField( firstInstance.getId().getType(), firstField ).toBlocking().lastOrDefault( null );
+ final Id idFirst = manager.getIdField( firstInstance.getId().getType(), firstField )
+ .toBlocking().lastOrDefault( null );
assertNull(idFirst);
- final Id idSecond = manager.getIdField( secondInstance.getId().getType(), secondField ).toBlocking().lastOrDefault( null );
+ final Id idSecond = manager.getIdField( secondInstance.getId().getType(), secondField )
+ .toBlocking().lastOrDefault( null );
assertNotNull( idSecond );
assertEquals( secondInstance.getId(), idSecond );
@@ -619,7 +625,6 @@ public class EntityCollectionManagerIT {
ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) );
-
final EntityCollectionManager manager = factory.createCollectionManager( context );
final Entity newEntity = new Entity( new SimpleId( "test" ) );
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyIT.java
index 15be420..f9ad211 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyIT.java
@@ -18,6 +18,7 @@
package org.apache.usergrid.persistence.collection.mvcc.stage.write;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,6 +42,9 @@ import org.apache.usergrid.persistence.model.field.StringField;
import com.google.inject.Inject;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -53,6 +57,9 @@ import static org.junit.Assert.fail;
public class WriteUniqueVerifyIT {
@Inject
+ private EntityCollectionManagerFactory factory;
+
+ @Inject
SerializationFig serializationFig;
@Inject
@@ -62,6 +69,17 @@ public class WriteUniqueVerifyIT {
@Inject
public EntityCollectionManagerFactory cmf;
+ private static AtomicBoolean startedAkka = new AtomicBoolean( false );
+
+ @Before
+ public void initAkka() {
+ if ( !startedAkka.getAndSet( true ) ) {
+ ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) );
+ EntityCollectionManager manager = factory.createCollectionManager( context );
+ manager.startAkkaForTesting( "127.0.0.1", 2551, "us-east" );
+ }
+ }
+
@Test
public void testConflict() {
@@ -96,9 +114,7 @@ public class WriteUniqueVerifyIT {
} catch ( Exception ex ) {
WriteUniqueVerifyException e = (WriteUniqueVerifyException)ex;
-
- // verify two unique value violations
- assertEquals( 2, e.getVioliations().size() );
+ assertTrue( !e.getVioliations().isEmpty() );
}
// ensure we can update original entity without error
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
index 1b0c7e4..827212a 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteUniqueVerifyTest.java
@@ -18,6 +18,11 @@
package org.apache.usergrid.persistence.collection.mvcc.stage.write;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,6 +44,8 @@ import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.MutationBatch;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import static org.apache.usergrid.persistence.collection.mvcc.stage.TestEntityGenerator.fromEntity;
import static org.apache.usergrid.persistence.collection.mvcc.stage.TestEntityGenerator.generateEntity;
import static org.mockito.Mockito.mock;
@@ -52,8 +59,10 @@ import static org.mockito.Mockito.when;
public class WriteUniqueVerifyTest {
@Inject
- private UniqueValueSerializationStrategy uvstrat;
+ private EntityCollectionManagerFactory factory;
+ @Inject
+ private UniqueValueSerializationStrategy uvstrat;
@Inject
@Rule
@@ -68,6 +77,18 @@ public class WriteUniqueVerifyTest {
private CassandraConfig cassandraConfig;
+ private static AtomicBoolean startedAkka = new AtomicBoolean( false );
+
+ @Before
+ public void initAkka() {
+ if ( !startedAkka.getAndSet( true ) ) {
+ ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) );
+ EntityCollectionManager manager = factory.createCollectionManager( context );
+ manager.startAkkaForTesting( "127.0.0.1", 2551, "us-east" );
+ }
+ }
+
+
@Test
public void testNoFields() throws ConnectionException {
final ApplicationScope collectionScope = mock( ApplicationScope.class );
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/rest/src/test/java/org/apache/usergrid/rest/UniqueValuesIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/UniqueValuesIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/UniqueValuesIT.java
index 2eaa4a7..6303e89 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/UniqueValuesIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/UniqueValuesIT.java
@@ -23,6 +23,7 @@ import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,6 +46,13 @@ import java.util.concurrent.atomic.AtomicInteger;
import static com.codahale.metrics.MetricRegistry.name;
+/**
+ * Tests that Usergrid will not allow creation of Users with duplicate usernames.
+ *
+ * Intended for use against a production-like cluster, not run during normal JUnit testing.
+ *
+ * Comment out the @Ignore annotation below and edit to add your target hosts.
+ */
public class UniqueValuesIT {
private static final Logger logger = LoggerFactory.getLogger( UniqueValuesIT.class );
@@ -53,11 +61,12 @@ public class UniqueValuesIT {
private static final AtomicInteger dupCounter = new AtomicInteger( 0 );
@Test
- public void testBasicOperation() throws Exception {
+ @Ignore("Intended for use against prod-like cluster")
+ public void testDuplicatePrevention() throws Exception {
- int numThreads = 3;
+ int numThreads = 6;
int poolsize = 40;
- int numUsers = 10;
+ int numUsers = 100;
Multimap<String, Form> usersCreated = Multimaps.synchronizedMultimap( HashMultimap.create() );
Multimap<String, Form> dupsRejected = Multimaps.synchronizedMultimap( HashMultimap.create() );
http://git-wip-us.apache.org/repos/asf/usergrid/blob/02c17959/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index c212fff..48e125b 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -223,47 +223,6 @@ public class CollectionsResourceIT extends AbstractRestIT {
}
@Test
- public void verifyThatFieldsIsRequiredForCollectionSchema() throws Exception {
- ArrayList<String> indexingArray = new ArrayList<>( );
-
- //field "fields" is required.
- Entity payload = new Entity();
- payload.put( "fieldWeirdnessNotFields", indexingArray);
-
- //Post index to the collection metadata
- try {
- this.app().collection( "testCollections" ).collection( "_settings" ).post( payload );
- fail();
- }catch(BadRequestException bre){
- //this is expected.
- }
-
- //ensure that it has to be an arraylist passed in.
- Map indexingMap = new HashMap<>( );
- indexingMap.put( "exludeStuff","randomtext" );
-
- payload = new Entity();
- payload.put( "fields", indexingMap);
-
- try {
- this.app().collection( "testCollections" ).collection( "_settings" ).post( payload );
- fail();
- }catch(BadRequestException bre){
- //this is expected.
- }
-
- payload = new Entity();
- payload.put( "fields", indexingArray);
-
- try {
- this.app().collection( "testCollections" ).collection( "_settings" ).post( payload );
- }catch(BadRequestException bre){
- fail( "This shouldn't fail" );
- }
-
- }
-
- @Test
public void postCollectionSchemaWithWildcardIndexAll() throws Exception {
// setup collection with index all