Author: [email protected] Date: Fri May 4 17:39:58 2012 New Revision: 2315 Log: [AMDATUCASSANDRA-183] Added files removed for unknown reasons
Added: trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/osgi/ trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/osgi/Activator.java trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/service/ trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/service/CassandraTest.java trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/service/RESTPerformanceTest.java trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/service/TestColumnFamilyProvider.java Added: trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/osgi/Activator.java ============================================================================== --- (empty file) +++ trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/osgi/Activator.java Fri May 4 17:39:58 2012 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu 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.amdatu.cassandra.test.performance.osgi; + +import org.amdatu.cassandra.client.CassandraClientService; +import org.amdatu.cassandra.listener.ColumnFamilyAvailable; +import org.amdatu.cassandra.listener.ColumnFamilyProvider; +import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager; +import org.amdatu.cassandra.persistencemanager.hector.HectorCassandraPersistenceManager; +import org.amdatu.cassandra.test.performance.service.RESTPerformanceTest; +import org.amdatu.cassandra.test.performance.service.TestColumnFamilyProvider; +import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator; +import org.amdatu.web.httpcontext.ResourceProvider; +import org.amdatu.web.rest.jaxrs.JaxRsSpi; + +import org.apache.felix.dm.DependencyManager; +import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; + +/** + * This is the activator for the UserAdmin REST API bundle. + * + * @author ivol + */ +public class Activator extends ServiceDependentActivator { + + @Override + protected Class<?>[] getRequiredServices() { + return new Class<?>[] {JaxRsSpi.class}; + } + + public void initWithDependencies(final BundleContext context, final DependencyManager manager) throws Exception { + // Create and register the TestColumnFamilyProvider service. + manager.add( + createComponent() + .setInterface(ColumnFamilyProvider.class.getName(), null) + .setImplementation(TestColumnFamilyProvider.class)); + + // Create the users resource service and register it as REST service + String keyspaceFilter = + "(" + CassandraPersistenceManager.KEYSPACE_AWARE_KEY + "=" + TestColumnFamilyProvider.KEYSPACE + ")"; + String cfFilter1 = "(" + ColumnFamilyAvailable.FILTER_NAME + "=" + TestColumnFamilyProvider.SUPER_CF + ")"; + String cfFilter2 = "(" + ColumnFamilyAvailable.FILTER_NAME + "=" + TestColumnFamilyProvider.STANDARD_CF + ")"; + String cfFilter3 = "(" + ColumnFamilyAvailable.FILTER_NAME + "=" + TestColumnFamilyProvider.ROWKEY_CF + ")"; + manager.add(createComponent() + .setInterface(ResourceProvider.class.getName(), null) + .setImplementation(RESTPerformanceTest.class) + .add(createServiceDependency().setService(LogService.class).setRequired(true)) + .add(createServiceDependency().setService(CassandraClientService.class).setRequired(true)) + .add( + createServiceDependency().setService(HectorCassandraPersistenceManager.class, keyspaceFilter) + .setRequired(true)) + .add(createServiceDependency().setService(ColumnFamilyAvailable.class, cfFilter1).setRequired(true)) + .add(createServiceDependency().setService(ColumnFamilyAvailable.class, cfFilter2).setRequired(true)) + .add(createServiceDependency().setService(ColumnFamilyAvailable.class, cfFilter3).setRequired(true))); + } + + @Override + public void destroy(final BundleContext bundleContext, final DependencyManager dependencyManager) throws Exception { + } +} Added: trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/service/CassandraTest.java ============================================================================== --- (empty file) +++ trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/service/CassandraTest.java Fri May 4 17:39:58 2012 @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu 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.amdatu.cassandra.test.performance.service; + +import static org.amdatu.cassandra.test.performance.service.TestColumnFamilyProvider.KEYSPACE; + +import org.amdatu.cassandra.client.CassandraClientService; +import org.amdatu.cassandra.listener.ColumnFamilyDefinition.ColumnType; +import org.amdatu.cassandra.listener.ColumnFamilyDefinition.CompareType; +import org.amdatu.cassandra.persistencemanager.hector.HectorCassandraPersistenceManager; + +import org.apache.cassandra.thrift.InvalidRequestException; +import org.apache.cassandra.thrift.NotFoundException; +import org.apache.thrift.TException; + +public class CassandraTest { + /** + * Amount of super columns under test. + */ + public static final int SUPERCOLS = 5; + + /** + * Amount of columns under test. + */ + public static final int COLS = 5; + + /** + * Amount of super rows under test. + */ + public static final int ROWS = 50; + + private HectorCassandraPersistenceManager m_pm; + private CassandraClientService m_daemon; + + public CassandraTest(final CassandraClientService daemon, final HectorCassandraPersistenceManager pm) + throws NotFoundException, + InvalidRequestException, TException { + m_pm = pm; + m_daemon = daemon; + } + + public String createPrivateColumnFamily(final String name) throws NotFoundException, + InvalidRequestException, TException { + long start = System.currentTimeMillis(); + if (!m_daemon.columnFamilyExists(KEYSPACE, name)) { + m_daemon.addColumnFamily(KEYSPACE, name, ColumnType.SUPER.getValue(), CompareType.BYTESTYPE.getValue(), + CompareType.BYTESTYPE.getValue()); + } + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } + + public String testSetValue(final String cfName, final String rowPrefix, final boolean isSuper) { + long start = System.currentTimeMillis(); + for (int i = 0; i < ROWS; i++) { + for (int j = 0; j < COLS; j++) { + if (isSuper) { + m_pm.setValue(cfName, rowPrefix + "row_" + i, "super", "column_" + j, "value_" + i); + } + else { + m_pm.setValue(cfName, rowPrefix + "row_" + i, null, "column_" + j, "value_" + i); + } + } + } + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } + + public String testGetValue(final String cfName, final String rowPrefix, final boolean isSuper) { + long start = System.currentTimeMillis(); + for (int i = 0; i < ROWS; i++) { + for (int j = 0; j < COLS; j++) { + if (isSuper) { + m_pm.getValue(cfName, rowPrefix + "row_" + i, "super", "column_" + j, String.class); + } + else { + m_pm.getValue(cfName, rowPrefix + "row_" + i, null, "column_" + j, String.class); + } + } + } + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } + + public String testGetRowKeys(final String cfName) { + long start = System.currentTimeMillis(); + for (int i = 0; i < 10; i++) { + m_pm.getRowKeys(cfName); + } + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } + + public String testSmartGetRowKeys(final String cfName) { + long start = System.currentTimeMillis(); + for (int i = 0; i < 10; i++) { + m_pm.getRowKeys(cfName, "super", "column_0"); + } + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } + + public String testGetColumns(final String cfName, final String rowPrefix) { + long start = System.currentTimeMillis(); + for (int i = 0; i < ROWS; i++) { + m_pm.getColumns(cfName, rowPrefix + "row_" + i, String.class); + } + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } + + public String testGetSuperColumns(final String cfName, final String rowPrefix) { + long start = System.currentTimeMillis(); + for (int i = 0; i < ROWS; i++) { + m_pm.getSuperColumns(cfName, rowPrefix + "row_" + i, String.class); + } + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } + + public String testGetRows(final String cfName) { + long start = System.currentTimeMillis(); + m_pm.getRows(cfName, String.class); + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } + + public String testGetSuperRows(final String cfName) { + long start = System.currentTimeMillis(); + m_pm.getSuperRows(cfName, String.class); + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } + + public String testRemoveRows(final String cfName, final String rowPrefix) { + long start = System.currentTimeMillis(); + for (int i = 0; i < ROWS; i++) { + m_pm.deleteRow(cfName, rowPrefix + "row_" + i); + } + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } +} Added: trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/service/RESTPerformanceTest.java ============================================================================== --- (empty file) +++ trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/service/RESTPerformanceTest.java Fri May 4 17:39:58 2012 @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu 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.amdatu.cassandra.test.performance.service; + +import org.amdatu.cassandra.client.CassandraClientService; +import org.amdatu.cassandra.persistencemanager.hector.HectorCassandraPersistenceManager; +import org.amdatu.web.httpcontext.ResourceProvider; + +import java.net.URL; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.CacheControl; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.osgi.service.log.LogService; + +/** + */ +@Path("performancetest") +public class RESTPerformanceTest implements ResourceProvider { + private volatile LogService m_logService; + + // Disable HTTP caching in this REST interface + private static CacheControl CACHE_CONTROL; + static { + CACHE_CONTROL = new CacheControl(); + CACHE_CONTROL.setNoCache(true); + } + + // Service dependencies injected by the dependency manager + private CassandraClientService m_cassandraDaemon; + private HectorCassandraPersistenceManager m_pm; + + public void start() { + createRowKeyTestSet(); + m_logService.log(LogService.LOG_INFO, "Cassandra PM performance test REST interface started"); + } + + // NB: each performance test bundle must implement a GET /rest/performancetest/status. This is used + // by the launcher to detect if the REST performance test bundle is up and running and so tests can + // be started. + @GET + @Produces({MediaType.TEXT_PLAIN}) + @Path("status") + public Response status() { + return buildOK("Cassandra performancetest service online"); + } + + @GET + @Produces({MediaType.TEXT_PLAIN}) + @Path("cassandra/{cftype}/{prefix}/setvalue") + public Response testStandardSetValue(@PathParam("cftype") final String cfType, + @PathParam("prefix") final String rowPrefix) { + String result; + try { + result = new CassandraTest(m_cassandraDaemon, m_pm).testSetValue(getCF(cfType), rowPrefix, isSuper(cfType)); + } + catch (Exception e) { + throw new WebApplicationException(e); + } + return buildOK(result); + } + + @GET + @Produces({MediaType.TEXT_PLAIN}) + @Path("cassandra/{cftype}/{prefix}/getvalue") + public Response testSuperSetValue(@PathParam("cftype") final String cfType, + @PathParam("prefix") final String rowPrefix) { + String result; + try { + result = new CassandraTest(m_cassandraDaemon, m_pm).testGetValue(getCF(cfType), rowPrefix, isSuper(cfType)); + } + catch (Exception e) { + throw new WebApplicationException(e); + } + return buildOK(result); + } + + @GET + @Produces({MediaType.TEXT_PLAIN}) + @Path("cassandra/getrowkeys") + public Response testGetRowKeys() { + String result; + try { + result = new CassandraTest(m_cassandraDaemon, m_pm).testGetRowKeys(TestColumnFamilyProvider.SUPER_CF); + } + catch (Exception e) { + throw new WebApplicationException(e); + } + return buildOK(result); + } + + @GET + @Produces({MediaType.TEXT_PLAIN}) + @Path("cassandra/smartgetrowkeys") + public Response testSmartGlobalGetRowKeys() { + String result; + try { + result = new CassandraTest(m_cassandraDaemon, m_pm).testSmartGetRowKeys(TestColumnFamilyProvider.SUPER_CF); + } + catch (Exception e) { + throw new WebApplicationException(e); + } + return buildOK(result); + } + + @GET + @Produces({MediaType.TEXT_PLAIN}) + @Path("cassandra/{prefix}/getcolumns") + public Response testGetColumns(@PathParam("prefix") final String rowPrefix) { + String result; + try { + result = + new CassandraTest(m_cassandraDaemon, m_pm).testGetColumns(TestColumnFamilyProvider.STANDARD_CF, + rowPrefix); + } + catch (Exception e) { + throw new WebApplicationException(e); + } + return buildOK(result); + } + + @GET + @Produces({MediaType.TEXT_PLAIN}) + @Path("cassandra/{prefix}/getsupercolumns") + public Response testGetSuperColumns(@PathParam("prefix") final String rowPrefix) { + String result; + try { + result = + new CassandraTest(m_cassandraDaemon, m_pm).testGetSuperColumns(TestColumnFamilyProvider.SUPER_CF, + rowPrefix); + } + catch (Exception e) { + throw new WebApplicationException(e); + } + return buildOK(result); + } + + @GET + @Produces({MediaType.TEXT_PLAIN}) + @Path("cassandra/getrows") + public Response testGetRows() { + String result; + try { + result = new CassandraTest(m_cassandraDaemon, m_pm).testGetRows(TestColumnFamilyProvider.STANDARD_CF); + } + catch (Exception e) { + throw new WebApplicationException(e); + } + return buildOK(result); + } + + @GET + @Produces({MediaType.TEXT_PLAIN}) + @Path("cassandra/getsuperrows") + public Response testGetSuperRows() { + String result; + try { + result = new CassandraTest(m_cassandraDaemon, m_pm).testGetSuperRows(TestColumnFamilyProvider.SUPER_CF); + } + catch (Exception e) { + throw new WebApplicationException(e); + } + return buildOK(result); + } + + @GET + @Produces({MediaType.TEXT_PLAIN}) + @Path("cassandra/{cftype}/{prefix}/removerows") + public Response testRemoveRows(@PathParam("cftype") final String cfType, + @PathParam("prefix") final String rowPrefix) { + String result; + try { + result = new CassandraTest(m_cassandraDaemon, m_pm).testRemoveRows(getCF(cfType), rowPrefix); + } + catch (Exception e) { + throw new WebApplicationException(e); + } + return buildOK(result); + } + + protected Response buildOK(final String result) { + return Response.ok(result).cacheControl(CACHE_CONTROL).build(); + } + + public URL getResource(final String name) { + return null; + } + + public String getResourceId() { + return "performancetest"; + } + + private boolean isSuper(final String cfType) { + return "super".equals(cfType); + } + + private String getCF(final String cfType) { + if ("super".equals(cfType)) { + return TestColumnFamilyProvider.SUPER_CF; + } + else { + return TestColumnFamilyProvider.STANDARD_CF; + } + } + + private String createRowKeyTestSet() { + long start = System.currentTimeMillis(); + if (m_pm.getRowKeys(TestColumnFamilyProvider.ROWKEY_CF).size() == 0) { + for (int i = 0; i < CassandraTest.ROWS; i++) { + for (int j = 0; j < CassandraTest.SUPERCOLS; j++) { + for (int k = 0; k < CassandraTest.COLS; k++) { + String value = "thisisthevalue_" + i + "_" + j + "_" + k; + m_pm.setValue(TestColumnFamilyProvider.ROWKEY_CF, "row_" + i, "super_" + j, "column_" + k, + value); + } + } + } + } + long diff = System.currentTimeMillis() - start; + return "Test completed in " + diff + " milliseconds"; + } +} Added: trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/service/TestColumnFamilyProvider.java ============================================================================== --- (empty file) +++ trunk/amdatu-cassandra/test-performance/test-bundle/src/main/java/org/amdatu/cassandra/test/performance/service/TestColumnFamilyProvider.java Fri May 4 17:39:58 2012 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, 2011 The Amdatu 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.amdatu.cassandra.test.performance.service; + +import org.amdatu.cassandra.listener.ColumnFamilyDefinition; +import org.amdatu.cassandra.listener.ColumnFamilyDefinition.ColumnType; +import org.amdatu.cassandra.listener.ColumnFamilyDefinition.CompareType; +import org.amdatu.cassandra.listener.ColumnFamilyProvider; + +public class TestColumnFamilyProvider implements ColumnFamilyProvider { + /** + * Keyspace of the performance test. + */ + public static final String KEYSPACE = "PerformanceTestKeyspace"; + + /** + * Standard columnfamily of the performance test. + */ + public static final String STANDARD_CF = "PerformanceTestStandardCF"; + + /** + * Super column family of the performance test. + */ + public static final String SUPER_CF = "PerformanceTestSuperCF"; + + /** + * Row key column family of the performance test. + */ + public static final String ROWKEY_CF = "PerformanceTestRowKeyCF"; + + public ColumnFamilyDefinition[] getColumnFamilies() { + // Register column families for Friend, which is a ColumnFamily specific to this bundle + // <ColumnFamily Name="Friend" ColumnType="Super" CompareWith="BytesType" CompareSubcolumnsWith="BytesType" /> + ColumnFamilyDefinition colFamDef = + new ColumnFamilyDefinition(SUPER_CF, new String[] {KEYSPACE}, ColumnType.SUPER, CompareType.BYTESTYPE, + CompareType.BYTESTYPE); + ColumnFamilyDefinition colFamDef2 = + new ColumnFamilyDefinition(STANDARD_CF, new String[] {KEYSPACE}, ColumnType.STANDARD, + CompareType.BYTESTYPE, + null); + ColumnFamilyDefinition colFamDef3 = + new ColumnFamilyDefinition(ROWKEY_CF, new String[] {KEYSPACE}, ColumnType.SUPER, CompareType.BYTESTYPE, + CompareType.BYTESTYPE); + return new ColumnFamilyDefinition[] {colFamDef, colFamDef2, colFamDef3}; + } +} _______________________________________________ Amdatu-commits mailing list [email protected] http://lists.amdatu.org/mailman/listinfo/amdatu-commits
