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 2014/02/14 15:20:41 UTC
[1/2] git commit: minor formatting change only
Updated Branches:
refs/heads/two-dot-o 2f786ebac -> 185cebe30
minor formatting change only
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/03e7bc40
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/03e7bc40
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/03e7bc40
Branch: refs/heads/two-dot-o
Commit: 03e7bc4041db39a03e5e9f388bbd016e62ad8f8a
Parents: 2f786eb
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Feb 14 09:09:26 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Feb 14 09:09:26 2014 -0500
----------------------------------------------------------------------
.../impl/EntityCollectionManagerImpl.java | 143 +++++++++----------
1 file changed, 69 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/03e7bc40/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 2586285..b5b4cd4 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
@@ -55,13 +55,13 @@ import rx.util.functions.FuncN;
/**
* Simple implementation. Should perform writes, delete and load.
*
- * TODO T.N. maybe refactor the stage operations into their own classes for clarity and organization?
+ * TODO: maybe refactor the stage operations into their own classes for clarity and organization?
*
* @author tnine
*/
public class EntityCollectionManagerImpl implements EntityCollectionManager {
- private static final Logger logger = LoggerFactory.getLogger( EntityCollectionManagerImpl.class );
+ private static final Logger logger = LoggerFactory.getLogger(EntityCollectionManagerImpl.class);
private final CollectionScope collectionScope;
private final UUIDService uuidService;
@@ -84,18 +84,21 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
@Inject
- public EntityCollectionManagerImpl( final UUIDService uuidService, final WriteStart writeStart,
- final Scheduler scheduler, final WriteUniqueVerify writeVerifyUnique,
- final WriteOptimisticVerify writeOptimisticVerify,
- final WriteCommit writeCommit, final Load load, final DeleteStart deleteStart,
- final DeleteCommit deleteCommit,
- @Assisted final CollectionScope collectionScope ) {
-
+ public EntityCollectionManagerImpl(
+ final UUIDService uuidService,
+ final WriteStart writeStart,
+ final Scheduler scheduler,
+ final WriteUniqueVerify writeVerifyUnique,
+ final WriteOptimisticVerify writeOptimisticVerify,
+ final WriteCommit writeCommit,
+ final Load load,
+ final DeleteStart deleteStart,
+ final DeleteCommit deleteCommit,
+ @Assisted final CollectionScope collectionScope ) {
Preconditions.checkNotNull( uuidService, "uuidService must be defined" );
ValidationUtils.validateCollectionScope( collectionScope );
-
this.writeStart = writeStart;
this.writeVerifyUnique = writeVerifyUnique;
this.writeOptimisticVerify = writeOptimisticVerify;
@@ -104,7 +107,6 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
this.deleteStart = deleteStart;
this.deleteCommit = deleteCommit;
-
this.uuidService = uuidService;
this.scheduler = scheduler;
this.collectionScope = collectionScope;
@@ -113,19 +115,21 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
@Override
public Observable<Entity> write( final Entity entity ) {
- //do our input validation
- Preconditions.checkNotNull( entity, "Entity is required in the new stage of the mvcc write" );
+ //do our input validation
+ Preconditions.checkNotNull( entity,
+ "Entity is required in the new stage of the mvcc write" );
final Id entityId = entity.getId();
- Preconditions.checkNotNull( entityId, "The entity id is required to be set for an update operation" );
+ Preconditions.checkNotNull( entityId,
+ "The entity id is required to be set for an update operation" );
- Preconditions
- .checkNotNull( entityId.getUuid(), "The entity id uuid is required to be set for an update operation" );
+ Preconditions.checkNotNull( entityId.getUuid(),
+ "The entity id uuid is required to be set for an update operation" );
- Preconditions
- .checkNotNull( entityId.getType(), "The entity id type required to be set for an update operation" );
+ Preconditions.checkNotNull( entityId.getType(),
+ "The entity id type required to be set for an update operation" );
final UUID version = uuidService.newTimeUUID();
@@ -133,71 +137,64 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
EntityUtils.setVersion( entity, version );
- /**
- *fire the stages
- * TODO use our own scheduler to help with multitenancy here.
- * TODO writeOptimisticVerify and writeVerifyUnique should happen concurrently to reduce user wait time
- */
-
- //these 3 lines could be done in a single line, but they are on multiple lines for clarity
+ // fire the stages
+ // TODO use our own scheduler to help with multitenancy here.
+ // TODO writeOptimisticVerify and writeVerifyUnique should be concurrent to reduce wait time
+ // these 3 lines could be done in a single line, but they are on multiple lines for clarity
- //create our observable and start the write
+ // create our observable and start the write
CollectionIoEvent<Entity> writeData = new CollectionIoEvent<Entity>( collectionScope, entity );
Observable<CollectionIoEvent<MvccEntity>> observable =
- Observable.from( writeData ).subscribeOn( scheduler ).map( writeStart ).flatMap(
- new Func1<CollectionIoEvent<MvccEntity>, Observable<CollectionIoEvent<MvccEntity>>>() {
+ Observable.from( writeData ).subscribeOn( scheduler ).map( writeStart ).flatMap(
+ new Func1<CollectionIoEvent<MvccEntity>, Observable<CollectionIoEvent<MvccEntity>>>() {
+ @Override
+ public Observable<CollectionIoEvent<MvccEntity>> call(
+ final CollectionIoEvent<MvccEntity> mvccEntityCollectionIoEvent ) {
- @Override
- public Observable<CollectionIoEvent<MvccEntity>> call(
- final CollectionIoEvent<MvccEntity> mvccEntityCollectionIoEvent ) {
-
- //do the unique and optimistic steps in parallel
+ // do the unique and optimistic steps in parallel
- /**
- *unique function. Since there can be more than 1 unique value in this entity
- * the unique verification step itself is multiple parallel executions.
- * This is why we use "flatMap" instead of "map", which allows the
- * WriteVerifyUnique stage to execute multiple verification steps in parallel and
- * zip the results
- */
+ // unique function. Since there can be more than 1 unique value in this
+ // entity the unique verify step itself is multiple parallel executions.
+ // This is why we use "flatMap" instead of "map", which allows the
+ // WriteVerifyUnique stage to execute multiple verification steps in
+ // parallel and zip the results
- Observable<CollectionIoEvent<MvccEntity>> unique =
- Observable.from( mvccEntityCollectionIoEvent ).subscribeOn( scheduler )
- .flatMap( writeVerifyUnique);
+ Observable<CollectionIoEvent<MvccEntity>> unique =
+ Observable.from( mvccEntityCollectionIoEvent ).subscribeOn( scheduler )
+ .flatMap( writeVerifyUnique);
- //optimistic verification
- Observable<CollectionIoEvent<MvccEntity>> optimistic =
- Observable.from( mvccEntityCollectionIoEvent ).subscribeOn( scheduler )
- .map( writeOptimisticVerify );
+ // optimistic verification
+ Observable<CollectionIoEvent<MvccEntity>> optimistic =
+ Observable.from( mvccEntityCollectionIoEvent ).subscribeOn( scheduler )
+ .map( writeOptimisticVerify );
- //zip the results
- /**
- * TODO: Should the zip only return errors here, and if errors are present, we throw during the zip phase? I couldn't find "
- */
+ // zip the results
+ // TODO: Should the zip only return errors here, and if errors are present,
+ // we throw during the zip phase? I couldn't find "
- return Observable.zip( unique, optimistic, new Func2<CollectionIoEvent<MvccEntity>,
- CollectionIoEvent<MvccEntity>, CollectionIoEvent<MvccEntity>>() {
- @Override
- public CollectionIoEvent<MvccEntity> call(
- final CollectionIoEvent<MvccEntity> mvccEntityCollectionIoEvent,
- final CollectionIoEvent<MvccEntity> mvccEntityCollectionIoEvent2 ) {
+ return Observable.zip( unique, optimistic, new Func2<CollectionIoEvent<MvccEntity>,
+ CollectionIoEvent<MvccEntity>, CollectionIoEvent<MvccEntity>>() {
+ @Override
+ public CollectionIoEvent<MvccEntity> call(
+ final CollectionIoEvent<MvccEntity> mvccEntityCollectionIoEvent,
+ final CollectionIoEvent<MvccEntity> mvccEntityCollectionIoEvent2 ) {
- return mvccEntityCollectionIoEvent;
- }
- } );
- }
- } );
+ return mvccEntityCollectionIoEvent;
+ }
+ } );
+ }
+ } );
-// //execute all validation stages concurrently. Needs refactored when this is done. https://github
-// // .com/Netflix/RxJava/issues/627
-// observable =
-// Concurrent.concurrent( observable, scheduler, new WaitZip(), writeVerifyUnique, writeOptimisticVerify );
+ // execute all validation stages concurrently. Needs refactored when this is done.
+ // https://github.com/Netflix/RxJava/issues/627
+ // observable = Concurrent.concurrent( observable, scheduler, new WaitZip(),
+ // writeVerifyUnique, writeOptimisticVerify );
//return the commit result.
return observable.map( writeCommit );
@@ -207,14 +204,12 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
@Override
public Observable<Void> delete( final Id entityId ) {
-
Preconditions.checkNotNull( entityId, "Entity id is required in this stage" );
Preconditions.checkNotNull( entityId.getUuid(), "Entity id is required in this stage" );
Preconditions.checkNotNull( entityId.getType(), "Entity type is required in this stage" );
-
- return Observable.from( new CollectionIoEvent<Id>( collectionScope, entityId ) ).subscribeOn( scheduler )
- .map( deleteStart ).map( deleteCommit );
+ return Observable.from( new CollectionIoEvent<Id>( collectionScope, entityId ) )
+ .subscribeOn( scheduler ).map( deleteStart ).map( deleteCommit );
}
@@ -222,11 +217,11 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
public Observable<Entity> load( final Id entityId ) {
Preconditions.checkNotNull( entityId, "Entity id required in the load stage" );
- Preconditions.checkNotNull( entityId.getUuid(), "Entity id uuid required in the load stage" );
- Preconditions.checkNotNull( entityId.getType(), "Entity id type required in the load stage" );
+ Preconditions.checkNotNull( entityId.getUuid(), "Entity id uuid required in load stage");
+ Preconditions.checkNotNull( entityId.getType(), "Entity id type required in load stage");
- return Observable.from( new CollectionIoEvent<Id>( collectionScope, entityId ) ).subscribeOn( scheduler )
- .map( load );
+ return Observable.from( new CollectionIoEvent<Id>( collectionScope, entityId ) )
+ .subscribeOn( scheduler ).map( load );
}
[2/2] git commit: Fixing query-validator
Posted by sn...@apache.org.
Fixing query-validator
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/185cebe3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/185cebe3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/185cebe3
Branch: refs/heads/two-dot-o
Commit: 185cebe3054171366c90a56025f047f6770b3cc4
Parents: 03e7bc4
Author: Sungju Jin <su...@softwaregeeks.org>
Authored: Fri Feb 14 23:16:13 2014 +0900
Committer: Sungju Jin <su...@softwaregeeks.org>
Committed: Fri Feb 14 23:16:13 2014 +0900
----------------------------------------------------------------------
stack/pom.xml | 1 +
stack/query-validator/pom.xml | 205 +++++++----
.../query/validator/CassandraRunner.java | 199 -----------
.../usergrid/query/validator/QueryITSuite.java | 3 +-
.../query/validator/QueryValidationTest.java | 339 -------------------
.../query/validator/QueryValidatorRunner.java | 208 ------------
.../java/org/apache/usergrid/rest/ITSetup.java | 10 +-
7 files changed, 140 insertions(+), 825 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/185cebe3/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index 52dbaa8..6c695e9 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -176,6 +176,7 @@
<module>websocket</module>
<module>rest</module>
<module>launcher</module>
+ <module>query-validator</module>
<module>test-utils</module>
<module>build-tools</module>
</modules>
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/185cebe3/stack/query-validator/pom.xml
----------------------------------------------------------------------
diff --git a/stack/query-validator/pom.xml b/stack/query-validator/pom.xml
index 0ebdcda..4cdb708 100644
--- a/stack/query-validator/pom.xml
+++ b/stack/query-validator/pom.xml
@@ -14,14 +14,7 @@
<name>Usergrid Query Validator</name>
<description>Query validator tools for Usergrid system.</description>
<packaging>jar</packaging>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-report-plugin</artifactId>
- </plugin>
- </plugins>
- </reporting>
+
<build>
<resources>
<resource>
@@ -37,9 +30,7 @@
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
- <include>**/*.xml</include>
- <include>**/*.properties</include>
- <include>**/*.json</include>
+ <include>**/*</include>
</includes>
</testResource>
</testResources>
@@ -48,7 +39,16 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <testFailureIgnore>false</testFailureIgnore>
+ <argLine>-Xmx${ug.heapmax} -Xms${ug.heapmin} -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8</argLine>
+
+ <includes>
+ <include>**/*Suite.java</include>
+ </includes>
+ <excludes>
+ <!-- Need to exclude Suite tests to prevent double execution -->
+ <exclude>**/UserQueryIT.java</exclude>
+ </excludes>
+
</configuration>
</plugin>
@@ -77,9 +77,8 @@
<goal>test-jar</goal>
</goals>
<configuration>
- <classifier>tests</classifier>
<includes>
- <include>**/org/apache/usergrid/**</include>
+ <include>**/org/usergrid/**</include>
</includes>
</configuration>
</execution>
@@ -92,131 +91,189 @@
<groupId>org.apache.usergrid</groupId>
<artifactId>usergrid-config</artifactId>
<version>${project.version}</version>
- <scope>test</scope>
- <classifier>tests</classifier>
</dependency>
+
<dependency>
<groupId>org.apache.usergrid</groupId>
- <artifactId>usergrid-test-utils</artifactId>
+ <artifactId>usergrid-core</artifactId>
<version>${project.version}</version>
- <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <artifactId>commons-logging</artifactId>
+ <groupId>commons-logging</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
+
<dependency>
<groupId>org.apache.usergrid</groupId>
- <artifactId>usergrid-core</artifactId>
+ <artifactId>usergrid-rest</artifactId>
<version>${project.version}</version>
+ <classifier>classes</classifier>
<exclusions>
<exclusion>
- <artifactId>commons-logging</artifactId>
- <groupId>commons-logging</groupId>
+ <artifactId>servlet-api</artifactId>
+ <groupId>javax.servlet</groupId>
</exclusion>
</exclusions>
</dependency>
+
<dependency>
<groupId>org.apache.usergrid</groupId>
- <artifactId>usergrid-core</artifactId>
+ <artifactId>usergrid-rest</artifactId>
<version>${project.version}</version>
- <scope>test</scope>
- <classifier>tests</classifier>
+ <classifier>compiled-jsp</classifier>
</dependency>
+
<dependency>
<groupId>org.apache.usergrid</groupId>
- <artifactId>usergrid-launcher</artifactId>
+ <artifactId>usergrid-rest</artifactId>
<version>${project.version}</version>
- <scope>compile</scope>
+ <classifier>tests</classifier>
+ <scope>test</scope>
</dependency>
+
+ <!-- Apache Dependencies -->
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
</dependency>
+
+ <!-- SUN, Javax Package, and Other Com Dependencies -->
+
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ </dependency>
+
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>usergrid-config</artifactId>
+ <version>${project.version}</version>
<scope>test</scope>
+ <classifier>tests</classifier>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>usergrid-test-utils</artifactId>
+ <version>${project.version}</version>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jul-to-slf4j</artifactId>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>usergrid-core</artifactId>
+ <version>${project.version}</version>
<scope>test</scope>
+ <classifier>tests</classifier>
</dependency>
+
<dependency>
<groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <exclusions>
- <exclusion>
- <artifactId>commons-logging</artifactId>
- <groupId>commons-logging</groupId>
- </exclusion>
- </exclusions>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-expression</artifactId>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
+ <groupId>org.jvnet.mock-javamail</groupId>
+ <artifactId>mock-javamail</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
+ <groupId>org.hectorclient</groupId>
+ <artifactId>hector-test</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-core</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context-support</artifactId>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-logging-juli</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-jasper</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-jasper-el</artifactId>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jdbc</artifactId>
- <version>${org.springframework.version}</version>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-jsp-api</artifactId>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>juli</artifactId>
<scope>test</scope>
</dependency>
+
+ <!-- use the external test client. Just depend on the maven jetty plugin to launch jetty -->
<dependency>
- <groupId>org.xerial</groupId>
- <artifactId>sqlite-jdbc</artifactId>
- <version>3.7.2</version>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-external</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-core</artifactId>
+ <scope>test</scope>
</dependency>
+
+
+
<dependency>
<groupId>org.usergrid</groupId>
<artifactId>usergrid-java-client</artifactId>
- <version>0.0.3</version>
- <scope>compile</scope>
</dependency>
+
<dependency>
- <groupId>org.apache.usergrid</groupId>
- <artifactId>usergrid-rest</artifactId>
- <version>0.0.29-SNAPSHOT</version>
- <scope>test</scope>
- <classifier>tests</classifier>
- <type>jar</type>
+ <groupId>org.xerial</groupId>
+ <artifactId>sqlite-jdbc</artifactId>
+ <version>3.7.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <version>${org.springframework.version}</version>
</dependency>
+
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/185cebe3/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/CassandraRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/CassandraRunner.java b/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/CassandraRunner.java
deleted file mode 100644
index 802f842..0000000
--- a/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/CassandraRunner.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright 2014 The Apache Software Foundation.
- *
- * Licensed 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.query.validator;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.model.InitializationError;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-import java.io.File;
-import java.lang.annotation.Annotation;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import org.apache.cassandra.service.CassandraDaemon;
-import org.apache.usergrid.cassandra.DataControl;
-import org.apache.usergrid.cassandra.SchemaManager;
-
-public class CassandraRunner extends BlockJUnit4ClassRunner {
-
- private static final String TMP = "tmp";
- private static Logger logger = LoggerFactory.getLogger(CassandraRunner.class);
- private static ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
- private static ContextHolder contextHolder;
- private SchemaManager schemaManager;
-
- // TODO maybe put a 'holder' object in the executor and provide access to application context thusly?
- // TODO assume a static 'usergrid-test-context.xml' primer/starter file
-
- public CassandraRunner(Class<?> klass) throws InitializationError {
- super(klass);
- logger.info("CassandraRunner started with class {}", klass.getName());
- }
-
-
- public static <T> T getBean(String name, Class<T> requiredType) {
- return contextHolder.applicationContext.getBean(name, requiredType);
- }
-
- public static <T> T getBean(Class<T> requiredType) {
- return contextHolder.applicationContext.getBean(requiredType);
- }
-
- /**
- * Class-level run. The order of events are as follows:
- * - load spring (if not loaded)
- * - init cassandra (if not started)
- * - look for DataControl annotation on class and delegate
- * @param notifier
- */
- @Override
- public void run(RunNotifier notifier) {
- DataControl control = preTest(notifier);
- super.run(notifier);
- postTest(notifier, control);
-
- }
-
- protected DataControl preTest(RunNotifier notifier){
- maybeInit();
-
- // check for SchemaManager annotation
- DataControl control = null;
- for(Annotation ann : getTestClass().getAnnotations() ) {
- logger.info("examining annotation " + ann);
- if ( ann instanceof DataControl ) {
- logger.info("founda dataCOntrol annotation");
- control = (DataControl)ann;
- }
- }
- loadDataControl(control);
- maybeCreateSchema();
-
- return control;
- }
-
- protected void postTest(RunNotifier notifier, DataControl control){
- if ( control == null || !control.skipTruncate() ) {
- schemaManager.destroy();
- }
- logger.info("shutting down context");
- contextHolder.applicationContext.stop();
-
- }
-
-
- private void loadDataControl(DataControl dataControl) {
- if ( !contextHolder.applicationContext.isActive() ) {
- logger.info("restarting context...");
- contextHolder.applicationContext.refresh();
- }
-
- if ( dataControl != null ) {
- // TODO check for classpath and go static?
- logger.info("dataControl found - looking upma SchemaManager impl");
- schemaManager = getBean(dataControl.schemaManager(), SchemaManager.class);
- } else {
- logger.info("dataControl not found - using default SchemaManager impl");
- schemaManager = getBean(SchemaManager.class);
- }
-
-
- }
-
- private boolean maybeCreateSchema() {
- if ( schemaManager.exists() ) {
- logger.info("Schema existed");
- return false;
- }
- schemaManager.create();
- schemaManager.populateBaseData();
-
- return true;
- }
-
-
-
- private static void maybeInit() {
- if ( contextHolder != null ) {
- return;
- }
- logger.info("Initing CassandraRunner...");
-
- // TODO these should all be passed in as config options ... via spring?
- // TODO make sure these match up with configs
- // TODO one cassandra config in this project!
- // TODO log4j.properties required to be present
-
- System.setProperty("cassandra-foreground", "true");
- System.setProperty("log4j.defaultInitOverride","true");
- System.setProperty("log4j.configuration", "log4j.properties");
- //System.setProperty("cassandra.load_ring_state", "false");so
- //System.setProperty("cassandra.join_ring","false");
- System.setProperty("cassandra.ring_delay_ms","100");
-
- FileUtils.deleteQuietly(new File(TMP));
-
- contextHolder = new ContextHolder();
- try {
- executor.schedule(contextHolder, 3, TimeUnit.SECONDS).get();
- } catch (Exception ex) {
- logger.error("Could not schedule cassandra runner",ex);
- }
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- try {
- logger.error("In shutdownHook");
- stopCassandra();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- });
- }
-
- private static void stopCassandra() throws Exception {
- if (contextHolder != null && contextHolder.cassandraDaemon != null) {
- contextHolder.cassandraDaemon.deactivate();
- }
- executor.shutdown();
- executor.shutdownNow();
- }
-
- static class ContextHolder implements Runnable {
- ConfigurableApplicationContext applicationContext;
- CassandraDaemon cassandraDaemon;
-
- @Override
- public void run() {
- cassandraDaemon = new CassandraDaemon();
- cassandraDaemon.activate();
- String[] locations = {"usergrid-test-context.xml"};
- applicationContext = new ClassPathXmlApplicationContext(locations);
-
-
-
- //acbf.autowire(getTestClass().getJavaClass(),AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/185cebe3/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryITSuite.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryITSuite.java b/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryITSuite.java
index fd88cf2..8f92fc3 100644
--- a/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryITSuite.java
+++ b/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryITSuite.java
@@ -35,6 +35,5 @@ public class QueryITSuite {
//TODO Detecting current path
@ClassRule
- public static ITSetup serverResource = new ITSetup( cassandraResource );
- //public static ITSetup serverResource = new ITSetup( cassandraResource, "../rest/src/main/webapp" );
+ public static ITSetup serverResource = new ITSetup( cassandraResource, "../rest/src/main/webapp" );
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/185cebe3/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidationTest.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidationTest.java b/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidationTest.java
deleted file mode 100644
index 5054e45..0000000
--- a/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidationTest.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*******************************************************************************
- * Copyright 2013 baas.io
- *
- * Licensed 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.query.validator;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.Assert;
-
-/**
- * @author Sung-ju Jin(realbeast)
- */
-@RunWith(QueryValidatorRunner.class)
-public class QueryValidationTest {
-
- private QueryValidator validator;
-
- @Before
- public void setup() {
- validator = QueryValidatorRunner.getValidator();
- }
-
- @Test
- public void sexEqualAndNameEqual() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and name = 'judekim' LIMIT 10";
- String api = "SELECT * WHERE sex = 'male' AND name = 'judekim'";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void nameEqualAndSexEqual() {
- String sqlite = "SELECT * FROM users WHERE name = 'judekim' and sex = 'male' LIMIT 10";
- String api = "select * where name = 'judekim' and sex = 'male'";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void nameEqualAndSexEqual_limitL20() {
- String sqlite = "SELECT * FROM users WHERE name = 'judekim' and sex = 'male' LIMIT 20";
- String api = "select * where name = 'judekim' and sex = 'male'";
- int limit = 20;
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- request.getApiQuery().setLimit(limit);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualAndNameEqualExtra1() {
- String sqlite = "SELECT * FROM users WHERE sex = 'female' and name = 'curioe' LIMIT 10";
- String api = "select * where sex = 'female' and name = 'curioe'";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualOrNameEqual() {
- String sqlite = "SELECT * FROM users WHERE sex = 'female' or name = 'curioe' LIMIT 10";
- String api = "select * where sex = 'female' or name = 'curioe'";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void nameBeginswithAndSexEqualAndAgeGreaterthanequalOrSexEqual_sortNameDesc() {
- String sqlite = "SELECT * FROM users WHERE name LIKE 'a%' and sex = 'male' and age >= 35 or sex = 'female' ORDER BY name desc LIMIT 10";
- String api = "select * where name = 'a*' and sex = 'male' and age >= 35 or sex = 'female' order by name desc";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void nameBeginswithAndSexEqualAndAgeGreaterthanequalOrSexEqual_sortAddressAscNameDesc() {
- String sqlite = "SELECT * FROM users WHERE name LIKE 'a%' and sex = 'male' and age >= 35 or sex = 'female' ORDER BY address asc, name desc LIMIT 4";
- String api = "select * where name = 'a*' and sex = 'male' and age >= 35 or sex = 'female' order by address asc, name desc";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void nameBeginswithAndSexEqualAndAgeGreaterthanequalOrSexEqual_sortAddressAscNameDesc_limitL4() {
- String sqlite = "SELECT * FROM users WHERE name LIKE 'a%' and sex = 'male' and age >= 35 or sex = 'female' ORDER BY address asc, name desc LIMIT 4";
- String api = "select * where name = 'a*' and sex = 'male' and age >= 35 or sex = 'female' order by address asc, name desc";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqual_sortAgeDescExtra1() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' ORDER BY age desc LIMIT 10";
- String api = "select * where sex = 'male' order by age desc";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqual_sortAgeDescExtra2() {
- String sqlite = " SELECT * FROM users WHERE sex = 'female' ORDER BY age desc LIMIT 10";
- String api = "select * where sex = 'female' order by age desc";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualAndAgeGreaterthanequal() {
- String sqlite = " SELECT * FROM users WHERE sex = 'male' and age >= 35 LIMIT 10";
- String api = "select * where sex = 'male' and age >= 35";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualAndAgeGreaterthanequal_sortAgeDesc() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY age desc LIMIT 10";
- String api = "select * where sex = 'male' and age >= 35 order by age desc";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualAndAgeGreaterthanequal_sortNameDesc() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY name desc LIMIT 10";
- String api = "select * where sex = 'male' and age >= 35 order by name desc";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualAndAgeGreaterthanequal_sortAgeDesc_limitL100() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY age desc LIMIT 100";
- String api = "select * where sex = 'male' and age >= 35 order by age desc";
- int limit = 100;
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- request.getApiQuery().setLimit(limit);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void qlSexEqualAndAgeGreaterthanequal_sortNameDesc_limitL100() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY name desc LIMIT 100";
- String api = "select * where sex = 'male' and age >= 35 order by name desc";
- int limit = 100;
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- request.getApiQuery().setLimit(limit);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualAndAgeGreaterthanequalOrSexEqual() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 or sex = 'female' LIMIT 10";
- String api = "select * where sex = 'male' and age >= 35 or sex = 'female'";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualAndAgeGreaterthanequalOrSexEqual_sortAgeDesc() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 or sex = 'female' ORDER BY age desc LIMIT 10";
- String api = "select * where sex = 'male' and age >= 35 or sex = 'female' order by age desc";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void limitL12() {
- String sqlite = "SELECT * FROM users LIMIT 12";
- String api = null;
- int limit = 12;
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- request.getApiQuery().setLimit(limit);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualAndAgeGreaterthanequalOrSexEqual_sortNameDesc() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 or sex = 'female' ORDER BY name desc LIMIT 10";
- String api = "select * where sex = 'male' and age >= 35 or sex = 'female' order by name desc";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualAndAgeGreaterthanequalOrSexEqual_sortNameDesc_limitL100() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 or sex = 'female' ORDER BY name desc LIMIT 100";
- String api = "select * where sex = 'male' and age >= 35 or sex = 'female' order by name desc";
- int limit = 100;
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- request.getApiQuery().setLimit(limit);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void limitL11() {
- String sqlite = "SELECT * FROM users LIMIT 11";
- String api = null;
- int limit = 11;
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- request.getApiQuery().setLimit(limit);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void nameBeginswithAndSexEqualAndAgeGreaterthanequalOrSexEqual() {
- String sqlite = "SELECT * FROM users WHERE name LIKE 'a%' and sex = 'male' and age >= 20 or sex = 'female' LIMIT 10";
- String api = "select * where name = 'a*' and sex = 'male' and age >= 20 or sex = 'female'";
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void nameBeginswithAndSexEqualAndAgeGreaterthanequalOrSexEqual_limitL20() {
- String sqlite = "SELECT * FROM users WHERE name LIKE 'a%' and sex = 'male' and age >= 20 or sex = 'female' LIMIT 20";
- String api = "select * where name = 'a*' and sex = 'male' and age >= 20 or sex = 'female'";
- int limit = 20;
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- request.getApiQuery().setLimit(limit);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-
- @Test
- public void sexEqualAndAgeGreaterthanequal_sortAddressDesc_limitL100() {
- String sqlite = "SELECT * FROM users WHERE sex = 'male' and age >= 35 ORDER BY address desc LIMIT 100";
- String api = "select * where sex = 'male' and age >= 35 order by address desc";
- int limit = 100;
-
- QueryRequest request = new QueryRequest();
- request.setDbQuery(sqlite);
- request.getApiQuery().setQuery(api);
- request.getApiQuery().setLimit(limit);
- QueryResponse response = validator.execute(request);
- Assert.assertTrue(response.toString(), response.result());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/185cebe3/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidatorRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidatorRunner.java b/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidatorRunner.java
deleted file mode 100644
index 7e8143b..0000000
--- a/stack/query-validator/src/test/java/org/apache/usergrid/query/validator/QueryValidatorRunner.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*******************************************************************************
- * Copyright 2013 baas.io
- *
- * Licensed 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.query.validator;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.model.InitializationError;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.usergrid.cassandra.DataControl;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.utils.JsonUtils;
-
-import java.io.IOException;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import org.apache.usergrid.launcher.Server;
-import org.apache.usergrid.management.ManagementService;
-
-/**
- * @author Sung-ju Jin(realbeast)
- */
-public class QueryValidatorRunner extends CassandraRunner {
-
- private static Logger logger = LoggerFactory.getLogger(QueryValidatorRunner.class);
- private boolean enableLocalServer;
- private static StandaloneServer standaloneServer;
- private Properties properties;
- private static QueryValidator validator;
- private static boolean initialize = false;
-
- public QueryValidatorRunner(Class<?> klass) throws InitializationError {
- super(klass);
- }
-
- @Override
- protected DataControl preTest(RunNotifier notifier) {
- DataControl control = super.preTest(notifier);
- try {
- setup();
- } catch (InitializationError initializationError) {
- initializationError.printStackTrace();
- }
- return control;
- }
-
- public static QueryValidator getValidator() {
- return validator;
- }
-
- public synchronized void setup() throws InitializationError {
- if(initialize)
- return;
-
- try {
- logger.info("Loading initialize...");
- Thread.sleep(20*1000);
- } catch (InterruptedException e) {}
-
- validator = CassandraRunner.getBean(QueryValidator.class);
- properties = CassandraRunner.getBean("properties",Properties.class);
-
- if( validator == null || properties == null) {
- throw new InitializationError("Application context not loaded.");
- }
-
- String enableString = (String)properties.get("usergrid.query.validator.api.enablelocal");
- enableLocalServer = StringUtils.endsWithIgnoreCase("true", enableString);
- if( enableLocalServer ) {
- startStandaloneServer();
- try {
- logger.info("Loading standalone server...");
- Thread.sleep(20*1000);
- } catch (InterruptedException e) {}
- }
- initialize = true;
-
- String endpoint = (String)properties.get("usergrid.query.validator.api.endpoint");
- String organization = (String)properties.get("usergrid.query.validator.api.organization");
- String app = (String)properties.get("usergrid.query.validator.api.app");
- String email = (String)properties.get("usergrid.query.validator.api.authorize.email");
- String password = (String)properties.get("usergrid.query.validator.api.authorize.password");
-
- String collection = "user";
- List<Entity> entities = loadEntities(collection);
- QueryValidationConfiguration configuration = new QueryValidationConfiguration();
- configuration.setEndpointUri(endpoint);
- configuration.setOrg(organization);
- configuration.setEmail(email);
- configuration.setPassword(password);
- configuration.setApp(app);
- configuration.setCollection(collection);
- configuration.setEntities(entities);
- validator.setConfiguration(configuration);
- validator.setup();
-
- }
-
- private List<Entity> loadEntities(String collection) {
- String json = null;
- try {
- URL url = Thread.currentThread().getContextClassLoader().getResource(collection + ".json");
- json = FileUtils.readFileToString(FileUtils.toFile(url), Charset.forName("UTF-8"));
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- List<Entity> entities = new ArrayList<Entity>();
- List<Map<String, Object>> datas = (List<Map<String, Object>>) JsonUtils.parse(json);
- for(Map<String, Object> data : datas) {
- Entity entity = new QueryEntity();
- entity.setType(collection);
- entity.setProperties(data);
- entity.setCreated(System.currentTimeMillis());
- entity.setModified(entity.getCreated());
- entities.add(entity);
- }
- return entities;
- }
-
- private void startStandaloneServer() {
- standaloneServer = new StandaloneServer();
- try {
- Thread thread = new Thread(standaloneServer);
- thread.start();
- } catch (Exception ex) {
- logger.error("Could not schedule standalone server runner", ex);
- }
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- try {
- logger.error("In shutdownHook");
- stopServer();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- });
- boolean loaded = false;
- while (!loaded) {
- if( standaloneServer.server.isRunning() ) {
- if( standaloneServer.server.getManagementService() != null ) {
- loaded = true;
- continue;
- }
- }
- try {
- logger.info("Loding application context...");
- Thread.sleep(2*1000);
- } catch (InterruptedException e) {
- continue;
- }
- }
-
- if(loaded) {
- ManagementService managementService = standaloneServer.server.getManagementService();
- try {
- managementService.setup();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- logger.info("Finish start standalone server.");
- }
-
- static class StandaloneServer implements Runnable {
- public static Server server;
-
- public StandaloneServer() {
- server = new Server();
- }
-
- @Override
- public void run() {
- server.setInitializeDatabaseOnStart(true);
- server.setDaemon(false);
- server.startServer();
- }
-
- public void stop() {
- server.stopServer();
- }
- }
-
- private void stopServer() {
- standaloneServer.stop();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/185cebe3/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
index 626c175..539e7c6 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/ITSetup.java
@@ -50,13 +50,17 @@ public class ITSetup extends ExternalResource {
private Properties properties;
- public ITSetup( CassandraResource cassandraResource ) {
+ public ITSetup( CassandraResource cassandraResource) {
this.cassandraResource = cassandraResource;
tomcatResource = TomcatResource.instance;
-
-
+ tomcatResource.setWebAppsPath("src/main/webapp");
}
+ public ITSetup( CassandraResource cassandraResource, String webAppsPath ) {
+ this.cassandraResource = cassandraResource;
+ tomcatResource = TomcatResource.instance;
+ tomcatResource.setWebAppsPath(webAppsPath);
+ }
private boolean setupCalled = false;
private boolean ready = false;