Author: [email protected]
Date: Mon Apr  4 11:31:19 2011
New Revision: 935

Log:
[AMDATU-340] Initial bundle for Cassandra PM testing

Added:
   trunk/etc/performancetest-bundle/
   trunk/etc/performancetest-bundle/pom.xml
   trunk/etc/performancetest-bundle/src/
   trunk/etc/performancetest-bundle/src/main/
   trunk/etc/performancetest-bundle/src/main/java/
   trunk/etc/performancetest-bundle/src/main/java/org/
   trunk/etc/performancetest-bundle/src/main/java/org/amdatu/
   trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/
   trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/
   
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/osgi/
   
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/osgi/Activator.java
   
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/
   
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/CassandraTest.java
   
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/InitService.java
   
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/InitServiceImpl.java
   
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/RESTPerformanceTest.java
   
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/TestColumnFamilyProvider.java

Added: trunk/etc/performancetest-bundle/pom.xml
==============================================================================
--- (empty file)
+++ trunk/etc/performancetest-bundle/pom.xml    Mon Apr  4 11:31:19 2011
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.amdatu</groupId>
+    <artifactId>org.amdatu.core</artifactId>
+    <version>0.2.0-SNAPSHOT</version>
+  </parent>
+  <groupId>org.amdatu.test</groupId>
+  <artifactId>performance-bundle</artifactId>
+  <packaging>bundle</packaging>
+   <name>Amdatu - Performance test bundle</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.amdatu.web</groupId>
+      <artifactId>httpcontext</artifactId>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.web.rest</groupId>
+      <artifactId>jaxrs</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
+      <groupId>org.json</groupId>
+      <artifactId>json</artifactId>
+      <version>20090211</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.libraries</groupId>
+      <artifactId>utilities</artifactId>
+      <version>${project.version}</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.wink</groupId>
+      <artifactId>wink-assembly-aggregatejar-osgi</artifactId>
+      <version>${org.apache.wink.version}</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.cassandra</groupId>
+      <artifactId>application</artifactId>
+      <scope>provided</scope>
+      <version>${project.version}</version>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.cassandra</groupId>
+      <artifactId>persistencemanager</artifactId>
+      <scope>provided</scope>
+      <version>${project.version}</version>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.cassandra</groupId>
+      <artifactId>listener</artifactId>
+      <scope>provided</scope>
+      <version>${project.version}</version>
+      <type>bundle</type>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            
<Bundle-Activator>org.amdatu.test.performance.osgi.Activator</Bundle-Activator>
+            
<Bundle-SymbolicName>org.amdatu.test.performance-bundle</Bundle-SymbolicName>
+            <Embed-Dependency>json,utilities;scope=compile</Embed-Dependency>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/osgi/Activator.java
==============================================================================
--- (empty file)
+++ 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/osgi/Activator.java
      Mon Apr  4 11:31:19 2011
@@ -0,0 +1,78 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.test.performance.osgi;
+
+import org.amdatu.cassandra.application.CassandraDaemonService;
+import org.amdatu.cassandra.listener.ColumnFamilyAvailable;
+import org.amdatu.cassandra.listener.ColumnFamilyProvider;
+import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager;
+import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
+import org.amdatu.test.performance.service.InitService;
+import org.amdatu.test.performance.service.InitServiceImpl;
+import org.amdatu.test.performance.service.RESTPerformanceTest;
+import org.amdatu.test.performance.service.TestColumnFamilyProvider;
+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(BundleContext context, DependencyManager 
manager) throws Exception {
+        // Create and register the InitService service.
+        manager.add(
+            createComponent()
+            .setInterface(InitService.class.getName(), null)
+            .setImplementation(InitServiceImpl.class)
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true))
+            
.add(createServiceDependency().setService(CassandraDaemonService.class).setRequired(true)));
+        
+        // Create and register the TestColumnFamilyProvider service.
+        manager.add(
+            createComponent()
+            .setInterface(ColumnFamilyProvider.class.getName(), null)
+            .setImplementation(TestColumnFamilyProvider.class)
+            
.add(createServiceDependency().setService(InitService.class).setRequired(true)));
+        
+        // Create the users resource service and register it as REST service
+        String keyspaceFilter = "(" + 
CassandraPersistenceManager.KEYSPACE_AWARE_KEY + "=" + 
TestColumnFamilyProvider.KEYSPACE + ")";
+        String cfFilter = "(" + ColumnFamilyAvailable.FILTER_NAME + "=" + 
TestColumnFamilyProvider.GLOBAL_CF + ")";
+        manager.add(createComponent()
+            .setInterface(ResourceProvider.class.getName(), null)
+            .setImplementation(RESTPerformanceTest.class)
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true))
+            
.add(createServiceDependency().setService(CassandraDaemonService.class).setRequired(true))
+            
.add(createServiceDependency().setService(CassandraPersistenceManager.class, 
keyspaceFilter).setRequired(true))
+            
.add(createServiceDependency().setService(ColumnFamilyAvailable.class, 
cfFilter).setRequired(true))
+            
.add(createServiceDependency().setService(InitService.class).setRequired(true)));
+    }
+
+    @Override
+    public void destroy(BundleContext bundleContext, DependencyManager 
dependencyManager) throws Exception {
+    }
+}

Added: 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/CassandraTest.java
==============================================================================
--- (empty file)
+++ 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/CassandraTest.java
       Mon Apr  4 11:31:19 2011
@@ -0,0 +1,116 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.test.performance.service;
+
+import static 
org.amdatu.test.performance.service.TestColumnFamilyProvider.GLOBAL_CF;
+import static 
org.amdatu.test.performance.service.TestColumnFamilyProvider.KEYSPACE;
+
+import org.amdatu.cassandra.application.CassandraDaemonService;
+import org.amdatu.cassandra.listener.ColumnFamilyDefinition.ColumnType;
+import org.amdatu.cassandra.listener.ColumnFamilyDefinition.CompareType;
+import org.amdatu.cassandra.persistencemanager.CassandraException;
+import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager;
+import org.apache.cassandra.thrift.InvalidRequestException;
+import org.apache.cassandra.thrift.NotFoundException;
+import org.apache.thrift.TException;
+
+public class CassandraTest {
+    private final static int INSERTS = 500;
+    private static int COUNTER = 1;
+    private CassandraPersistenceManager m_pm;
+    private String m_privateCFName;
+
+    public CassandraTest(CassandraDaemonService daemon, 
CassandraPersistenceManager pm) throws NotFoundException, 
InvalidRequestException, TException {
+        m_pm = pm;
+        m_privateCFName = "CF_" + COUNTER++;
+        if (!daemon.columnFamilyExists(KEYSPACE, m_privateCFName)) {
+            daemon.addColumnFamily(KEYSPACE, m_privateCFName, 
ColumnType.SUPER.value, CompareType.BYTESTYPE.value,  
CompareType.BYTESTYPE.value);
+        }
+    }
+
+    public String testGlobalSetValue() throws CassandraException {
+        long start = System.currentTimeMillis();
+        for (int i=0; i<INSERTS; i++) {
+            m_pm.setValue(GLOBAL_CF, "row_" + i, "super", "column", 
"value_"+i);
+        }
+        long diff = System.currentTimeMillis() - start;
+        return "Test completed in " + diff + " milliseconds";
+    }
+
+    public String testPrivateSetValue() throws CassandraException {
+        long start = System.currentTimeMillis();
+        for (int i=0; i<INSERTS; i++) {
+            m_pm.setValue(m_privateCFName, "row_" + i, "super", "column", 
"value_"+i);
+        }
+        long diff = System.currentTimeMillis() - start;
+        return "Test completed in " + diff + " milliseconds";
+    }
+    
+    public String testGlobalGetRowKeys() throws CassandraException {
+        long start = System.currentTimeMillis();
+        for (int i=0; i<50; i++) {
+            m_pm.getRowKeys(GLOBAL_CF);
+        }
+        long diff = System.currentTimeMillis() - start;
+        return "Test completed in " + diff + " milliseconds";
+    }
+    
+    public String testPrivateGetRowKeys() throws CassandraException {
+        long start = System.currentTimeMillis();
+        for (int i=0; i<50; i++) {
+            m_pm.getRowKeys(m_privateCFName);
+        }
+        long diff = System.currentTimeMillis() - start;
+        return "Test completed in " + diff + " milliseconds";
+    }
+    
+    public String testGlobalGetSuperColumns() throws CassandraException {
+        long start = System.currentTimeMillis();
+        for (int i=0; i<INSERTS; i++) {
+            m_pm.getSuperColumns(GLOBAL_CF, "row_"+i, String.class);
+        }
+        long diff = System.currentTimeMillis() - start;
+        return "Test completed in " + diff + " milliseconds";
+    }
+    
+    public String testPrivateGetSuperColumns() throws CassandraException {
+        long start = System.currentTimeMillis();
+        for (int i=0; i<INSERTS; i++) {
+            m_pm.getSuperColumns(m_privateCFName, "row_"+i, String.class);
+        }
+        long diff = System.currentTimeMillis() - start;
+        return "Test completed in " + diff + " milliseconds";
+    }
+    
+    public String testGlobalRemoveRows() throws CassandraException {
+        long start = System.currentTimeMillis();
+        for (int i=0; i<INSERTS; i++) {
+            m_pm.deleteRow(GLOBAL_CF, "row_"+i);
+        }
+        long diff = System.currentTimeMillis() - start;
+        return "Test completed in " + diff + " milliseconds";
+    }
+    
+    public String testPrivateRemoveRows() throws CassandraException {
+        long start = System.currentTimeMillis();
+        for (int i=0; i<INSERTS; i++) {
+            m_pm.deleteRow(m_privateCFName, "row_"+i);
+        }
+        long diff = System.currentTimeMillis() - start;
+        return "Test completed in " + diff + " milliseconds";
+    }
+}

Added: 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/InitService.java
==============================================================================
--- (empty file)
+++ 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/InitService.java
 Mon Apr  4 11:31:19 2011
@@ -0,0 +1,5 @@
+package org.amdatu.test.performance.service;
+
+public interface InitService {
+
+}

Added: 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/InitServiceImpl.java
==============================================================================
--- (empty file)
+++ 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/InitServiceImpl.java
     Mon Apr  4 11:31:19 2011
@@ -0,0 +1,21 @@
+package org.amdatu.test.performance.service;
+
+import org.amdatu.cassandra.application.CassandraDaemonService;
+import org.apache.cassandra.thrift.InvalidRequestException;
+import org.apache.thrift.TException;
+import org.osgi.service.log.LogService;
+
+public class InitServiceImpl implements InitService {
+    private volatile CassandraDaemonService m_cassandraDaemon;
+    private volatile LogService m_logService;
+
+    public void start() throws TException, InvalidRequestException {
+        // This service removes the test keyspace if it exists, to ensure that 
upon startup
+        // everything is 'clean'
+        if 
(m_cassandraDaemon.keyspaceExists(TestColumnFamilyProvider.KEYSPACE)) {
+            m_logService.log(LogService.LOG_WARNING, "Dropping keyspace '" + 
TestColumnFamilyProvider.KEYSPACE + "', this may take some time...");
+            m_cassandraDaemon.dropKeyspace(TestColumnFamilyProvider.KEYSPACE);
+            m_logService.log(LogService.LOG_WARNING, "Dropping keyspace 
finished.");
+        }
+    }
+}

Added: 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/RESTPerformanceTest.java
==============================================================================
--- (empty file)
+++ 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/RESTPerformanceTest.java
 Mon Apr  4 11:31:19 2011
@@ -0,0 +1,164 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.test.performance.service;
+
+
+import java.net.URL;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+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.amdatu.cassandra.application.CassandraDaemonService;
+import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager;
+import org.amdatu.web.httpcontext.ResourceProvider;
+
+/**
+ */
+@Path("performancetest")
+public class RESTPerformanceTest implements ResourceProvider {
+    // Disable HTTP caching in this REST interface
+    private static CacheControl m_cacheControl;
+    static {
+        m_cacheControl = new CacheControl();
+        m_cacheControl.setNoCache(true);
+    }
+
+    // Service dependencies injected by the dependency manager
+    private CassandraDaemonService m_cassandraDaemon;
+    private CassandraPersistenceManager m_pm;
+
+    @GET
+    @Produces({MediaType.TEXT_PLAIN})
+    @Path("cassandra/global/setvalue")
+    public Response testGlobalSetValue() {
+        String result;
+        try {
+            result = new CassandraTest(m_cassandraDaemon, 
m_pm).testGlobalSetValue();
+        } catch (Exception e) {
+            throw new WebApplicationException(e);
+        }
+        return buildOK(result);
+    }
+
+    @GET
+    @Produces({MediaType.TEXT_PLAIN})
+    @Path("cassandra/private/setvalue")
+    public Response testPrivateSetValue() {
+        String result;
+        try {
+            result = new CassandraTest(m_cassandraDaemon, 
m_pm).testPrivateSetValue();
+        } catch (Exception e) {
+            throw new WebApplicationException(e);
+        }
+        return buildOK(result);
+    }
+
+    @GET
+    @Produces({MediaType.TEXT_PLAIN})
+    @Path("cassandra/global/getrowkeys")
+    public Response testGlobalGetRowKeys() {
+        String result;
+        try {
+            result = new CassandraTest(m_cassandraDaemon, 
m_pm).testGlobalGetRowKeys();
+        } catch (Exception e) {
+            throw new WebApplicationException(e);
+        }
+        return buildOK(result);
+    }
+
+    @GET
+    @Produces({MediaType.TEXT_PLAIN})
+    @Path("cassandra/private/getrowkeys")
+    public Response testPrivateGetRowKeys() {
+        String result;
+        try {
+            result = new CassandraTest(m_cassandraDaemon, 
m_pm).testPrivateGetRowKeys();
+        } catch (Exception e) {
+            throw new WebApplicationException(e);
+        }
+        return buildOK(result);
+    }
+    
+    @GET
+    @Produces({MediaType.TEXT_PLAIN})
+    @Path("cassandra/global/getsupercolumns")
+    public Response testGlobalGetSuperColumns() {
+        String result;
+        try {
+            result = new CassandraTest(m_cassandraDaemon, 
m_pm).testGlobalGetSuperColumns();
+        } catch (Exception e) {
+            throw new WebApplicationException(e);
+        }
+        return buildOK(result);
+    }
+
+    @GET
+    @Produces({MediaType.TEXT_PLAIN})
+    @Path("cassandra/private/getsupercolumns")
+    public Response testPrivateGetSuperColumns() {
+        String result;
+        try {
+            result = new CassandraTest(m_cassandraDaemon, 
m_pm).testPrivateGetSuperColumns();
+        } catch (Exception e) {
+            throw new WebApplicationException(e);
+        }
+        return buildOK(result);
+    }
+
+    @GET
+    @Produces({MediaType.TEXT_PLAIN})
+    @Path("cassandra/global/removerows")
+    public Response testGlobalRemoveRows() {
+        String result;
+        try {
+            result = new CassandraTest(m_cassandraDaemon, 
m_pm).testGlobalRemoveRows();
+        } catch (Exception e) {
+            throw new WebApplicationException(e);
+        }
+        return buildOK(result);
+    }
+
+    @GET
+    @Produces({MediaType.TEXT_PLAIN})
+    @Path("cassandra/private/removerows")
+    public Response testPrivateRemoveRows() {
+        String result;
+        try {
+            result = new CassandraTest(m_cassandraDaemon, 
m_pm).testPrivateRemoveRows();
+        } catch (Exception e) {
+            throw new WebApplicationException(e);
+        }
+        return buildOK(result);
+    }
+    
+    protected Response buildOK(String result) {
+        return Response.ok(result).cacheControl(m_cacheControl).build();
+    }
+
+    public URL getResource(String name) {
+        return null;
+    }
+
+    public String getResourceId() {
+        return "performancetest";
+    }
+}

Added: 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/TestColumnFamilyProvider.java
==============================================================================
--- (empty file)
+++ 
trunk/etc/performancetest-bundle/src/main/java/org/amdatu/test/performance/service/TestColumnFamilyProvider.java
    Mon Apr  4 11:31:19 2011
@@ -0,0 +1,36 @@
+/*
+    Copyright (C) 2010 Amdatu.org
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.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 {
+    public final static String KEYSPACE = "PerformanceTestKeyspace";
+    public final static String GLOBAL_CF = "PerformanceTestGlobalCF";
+        
+    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(GLOBAL_CF, new String[]{KEYSPACE}, 
ColumnType.SUPER, CompareType.BYTESTYPE,
+                        CompareType.BYTESTYPE);
+        return new ColumnFamilyDefinition[]{colFamDef};
+    }
+}
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to