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/03/05 17:20:50 UTC
[5/5] git commit: Simple stress tests.
Simple stress tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/de98a4a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/de98a4a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/de98a4a1
Branch: refs/heads/two-dot-o
Commit: de98a4a1e58081240064d56c5d0aa3dc56cf505b
Parents: 5eaf05a
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Mar 5 10:23:51 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Mar 5 10:23:51 2014 -0500
----------------------------------------------------------------------
.../collection/EntityCollectionManagerST.java | 89 ++++++++++++++++++++
.../index/impl/EntityCollectionIndexST.java | 78 +++++++++++++++++
2 files changed, 167 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/de98a4a1/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java
new file mode 100644
index 0000000..e989942
--- /dev/null
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+package org.apache.usergrid.persistence.collection;
+
+import com.google.inject.Inject;
+import org.apache.commons.lang3.time.StopWatch;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import static org.junit.Assert.assertNotNull;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import rx.Observable;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules(TestCollectionModule.class)
+public class EntityCollectionManagerST {
+ private static final Logger log = LoggerFactory.getLogger( EntityCollectionManagerST.class );
+
+ @Inject
+ private EntityCollectionManagerFactory factory;
+
+ @ClassRule
+ public static CassandraRule rule = new CassandraRule();
+
+ @Inject
+ @Rule
+ public MigrationManagerRule migrationManagerRule;
+
+ @Test
+ public void writeThousands() {
+
+ CollectionScope context = new CollectionScopeImpl(
+ new SimpleId("organization"), new SimpleId("test"), "test");
+
+ EntityCollectionManager manager = factory.createCollectionManager(context);
+
+ int limit = 10000;
+
+ StopWatch timer = new StopWatch();
+ timer.start();
+
+ for (int i = 0; i < limit; i++) {
+
+ Entity newEntity = new Entity(new SimpleId("test"));
+ Observable<Entity> observable = manager.write(newEntity);
+ Entity returned = observable.toBlockingObservable().lastOrDefault(null);
+ assertNotNull("Returned has a id", returned.getId());
+ assertNotNull("Returned has a version", returned.getVersion());
+
+ Entity fetched = manager.load( returned.getId() ).toBlockingObservable().last();
+ assertNotNull("Returned has a id", fetched.getId());
+ assertNotNull("Returned has a version", fetched.getVersion());
+
+ if ( i % 1000 == 0 ) {
+ log.info(" Wrote: " + i);
+ }
+ }
+
+ timer.stop();
+ log.info( "Total time to write {} entries {}ms, average {}ms/entry",
+ limit, timer.getTime(), timer.getTime() / limit );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/de98a4a1/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexST.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexST.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexST.java
new file mode 100644
index 0000000..c2e693c
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexST.java
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+package org.apache.usergrid.persistence.index.impl;
+
+import com.google.inject.Inject;
+import java.io.IOException;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.time.StopWatch;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
+import org.apache.usergrid.persistence.collection.util.EntityUtils;
+import org.apache.usergrid.persistence.index.EntityCollectionIndex;
+import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
+import org.apache.usergrid.persistence.index.guice.TestIndexModule;
+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.field.StringField;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules(TestIndexModule.class)
+public class EntityCollectionIndexST {
+ private static final Logger log = LoggerFactory.getLogger( EntityCollectionIndexST.class );
+
+ @Inject
+ public EntityCollectionIndexFactory collectionIndexFactory;
+
+ @Test
+ public void indexThousands() throws IOException {
+
+ Id appId = new SimpleId("application");
+ Id orgId = new SimpleId("organization");
+ CollectionScope scope = new CollectionScopeImpl( appId, orgId, "contacts" );
+ EntityCollectionIndex index = collectionIndexFactory.createCollectionIndex( scope );
+
+ int limit = 10000;
+ StopWatch timer = new StopWatch();
+ timer.start();
+ for ( int i = 0; i < limit; i++ ) {
+
+ Entity entity = new Entity(new SimpleId(UUIDGenerator.newTimeUUID(), scope.getName()));
+ EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() );
+ entity.setField( new StringField( "name", RandomStringUtils.randomAlphabetic(20)) );
+
+ index.index( entity );
+
+ if ( i % 1000 == 0 ) {
+ log.info(" Indexed: " + i);
+ }
+ }
+ timer.stop();
+ log.info( "Total time to index {} entries {}ms, average {}ms/entry",
+ limit, timer.getTime(), timer.getTime() / limit );
+ }
+}