Author: ivol
Date: Thu Oct 21 15:48:54 2010
New Revision: 201
Log:
[AMDATU-110] Improved javadoc, added integration test and removed unused
libraries
Added:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/CassandraDaemonIntegrationTest.java
Removed:
trunk/platform-bundles/cassandra-application/src/main/resources/lib/avro-1.2.0-dev.jar
trunk/platform-bundles/cassandra-application/src/main/resources/lib/hadoop-core-0.20.1.jar
trunk/platform-bundles/cassandra-application/src/main/resources/lib/ivy-2.1.0.jar
trunk/platform-bundles/cassandra-application/src/main/resources/lib/jline-0.9.94.jar
trunk/platform-bundles/cassandra-application/src/main/resources/lib/libthrift-r917130.jar
trunk/platform-bundles/cassandra-application/src/main/resources/lib/log4j-1.2.15.jar
Modified:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
trunk/platform-bundles/cassandra-application/src/main/java/org/amdatu/platform/cassandra/application/CassandraDaemonService.java
trunk/platform-bundles/cassandra-application/src/main/java/org/amdatu/platform/cassandra/application/service/CassandraDaemonServiceImpl.java
Modified:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java
==============================================================================
---
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java
(original)
+++
trunk/integration-tests/src/test/java/org/amdatu/test/integration/IntegrationTestRunner.java
Thu Oct 21 15:48:54 2010
@@ -53,7 +53,7 @@
/**
* Inherited tests need to implement this method.
*/
- public abstract void run();
+ public abstract void run() throws Exception;
public Option[] configure() {
// First get our own JAR
@@ -119,7 +119,7 @@
bundle(integrationTestJarFile.toURI().toString())));
}
- public void runTest(String testName) {
+ public void runTest(String testName) throws Exception {
try {
// We need to sleep for some time since we need to make sure that
the framework is 'finished'
// starting. If we continue immediately the framework is stopped
immediately after finishing
Added:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/CassandraDaemonIntegrationTest.java
==============================================================================
--- (empty file)
+++
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/CassandraDaemonIntegrationTest.java
Thu Oct 21 15:48:54 2010
@@ -0,0 +1,111 @@
+/*
+ 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.integration.tests;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.amdatu.platform.cassandra.application.CassandraDaemonService;
+import
org.amdatu.platform.cassandra.listener.ColumnFamilyDefinition.ColumnType;
+import
org.amdatu.platform.cassandra.listener.ColumnFamilyDefinition.CompareType;
+import org.amdatu.test.integration.IntegrationTestRunner;
+import org.apache.cassandra.thrift.InvalidRequestException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+
+/**
+ * This class provides an integration test for the Cassandra Daemon service.
+ *
+ * @author ivol
+ */
+ at RunWith(JUnit4TestRunner.class)
+public class CassandraDaemonIntegrationTest extends IntegrationTestRunner {
+ private final static String KEYSPACE = "IntegrationTestKeySpace";
+ private final static String COLUMNFAMILY = "IntegrationTestColumnFamily";
+
+ private CassandraDaemonService m_daemonService;
+
+ @Configuration
+ public Option[] configure() {
+ return super.configure();
+ }
+
+ @Test
+ public void testCassandraDaemonService() throws Exception {
+ super.runTest("Cassandra Daemon Service");
+ }
+
+ public void run() throws Exception {
+ m_daemonService = getService(CassandraDaemonService.class);
+
+ // -1- Test adding/updating/removing keyspaces
+ int beforeCount = m_daemonService.getKeyspaces().size();
+ m_daemonService.addKeyspace(KEYSPACE);
+ Assert.assertTrue("Keyspace '" + KEYSPACE + "' does not exist after
creation", m_daemonService
+ .keyspaceExists(KEYSPACE));
+ try {
+ // Try to create keyspace with the same name twice, should throw a
InvalidRequestException
+ m_daemonService.addKeyspace(KEYSPACE);
+ Assert.fail("InvalidRequestException expected but not thrown");
+ }
+ catch (InvalidRequestException e) {}
+
+ // Case sensitivity check: Cassandra is case-sensitive!
+ m_daemonService.addKeyspace(KEYSPACE.toLowerCase());
+ m_daemonService.addKeyspace(KEYSPACE.toUpperCase());
+
+ // Get all keyspaces and check that all three have been created
+ List<String> allKeyspaces = m_daemonService.getKeyspaces();
+
+ Assert.assertTrue(allKeyspaces.contains(KEYSPACE));
+ Assert.assertTrue(allKeyspaces.contains(KEYSPACE.toLowerCase()));
+ Assert.assertTrue(allKeyspaces.contains(KEYSPACE.toUpperCase()));
+ Assert.assertTrue("Expected available keyspaces = " + (beforeCount +
3) + ", but actual = "
+ + allKeyspaces.size(), allKeyspaces.size() == beforeCount + 3);
+
+ // -2- Test adding/updating ColumnFamily's to the keyspace
+ m_daemonService.addColumnFamily(KEYSPACE, COLUMNFAMILY,
ColumnType.STANDARD.value,
+ CompareType.BYTESTYPE.value, CompareType.BYTESTYPE.value);
+ Assert.assertTrue("ColumnFamily '" + COLUMNFAMILY + "' does not exist
after creation", m_daemonService
+ .columnFamilyExists(KEYSPACE, COLUMNFAMILY));
+
+ try {
+ // Try to create ColumnFamily with the same name twice, should
throw a InvalidRequestException
+ m_daemonService.addColumnFamily(KEYSPACE, COLUMNFAMILY,
ColumnType.STANDARD.value,
+ CompareType.BYTESTYPE.value, CompareType.BYTESTYPE.value);
+ Assert.fail("InvalidRequestException expected but not thrown");
+ }
+ catch (InvalidRequestException e) {}
+
+ // Case sensitivity check
+ m_daemonService.addColumnFamily(KEYSPACE, COLUMNFAMILY.toLowerCase(),
ColumnType.STANDARD.value,
+ CompareType.BYTESTYPE.value, CompareType.BYTESTYPE.value);
+ m_daemonService.addColumnFamily(KEYSPACE, COLUMNFAMILY.toUpperCase(),
ColumnType.STANDARD.value,
+ CompareType.BYTESTYPE.value, CompareType.BYTESTYPE.value);
+
+ List<String> allColumnFamilies =
m_daemonService.getColumnFamilies(KEYSPACE);
+ Assert.assertTrue(allColumnFamilies.contains(COLUMNFAMILY));
+
Assert.assertTrue(allColumnFamilies.contains(COLUMNFAMILY.toLowerCase()));
+
Assert.assertTrue(allColumnFamilies.contains(COLUMNFAMILY.toUpperCase()));
+ Assert.assertTrue("Expected available ColumnFamily's = 3, but actual =
"
+ + allColumnFamilies.size(), allColumnFamilies.size() == 3);
+ }
+}
Modified:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
==============================================================================
---
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
(original)
+++
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/TenantManagementServiceTest.java
Thu Oct 21 15:48:54 2010
@@ -37,7 +37,6 @@
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
/**
* This class provides an integration test for testing the Tenant Management
Service.
@@ -53,11 +52,11 @@
}
@Test
- public void testTenantManagementService() {
+ public void testTenantManagementService() throws Exception {
super.runTest("Tenant Management Service");
}
- public void run() {
+ public void run() throws Exception {
// First we register a new in-memory TenantDAO service and register it
with a higher service rank then the default
// Cassandra DAO such that our test framework will pick it up
DependencyManager depMgr = new DependencyManager(m_bundleContext);
@@ -78,62 +77,56 @@
TenantManagementService tenantService =
getService(TenantManagementService.class);
System.out.println(TEST_PREFIX + "Testing " +
tenantService.getClass().getName());
+ Tenant[] allTenants = tenantService.getAllTenants();
+ Assert.assertTrue("There are already tenants present in the storage",
+ tenantService.getAllTenants().length == 0);
+
+ int tenantCount = allTenants.length;
+ Tenant tenant =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant",
"TEST");
+ tenantService.updateTenant(tenant);
+
+ Assert.assertTrue("Added and updated 1 tenant, but the Tenant service
now holds "
+ + tenantService.getAllTenants().length + " tenants, expected: " +
(tenantCount + 1), tenantService
+ .getAllTenants().length == tenantCount + 1);
+
+ // Try to add a tenant with the same id, should throw an exception
try {
- Tenant[] allTenants = tenantService.getAllTenants();
- Assert.assertTrue("There are already tenants present in the
storage",
- tenantService.getAllTenants().length == 0);
-
- int tenantCount = allTenants.length;
- Tenant tenant =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant",
"TEST");
- tenantService.updateTenant(tenant);
-
- Assert.assertTrue("Added and updated 1 tenant, but the Tenant
service now holds "
- + tenantService.getAllTenants().length + " tenants, expected:
" + (tenantCount + 1), tenantService
- .getAllTenants().length == tenantCount + 1);
-
- // Try to add a tenant with the same id, should throw an exception
- try {
-
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant",
"sdfsdfd");
- Assert.assertTrue("Tenant with the same id could be created
twice", false);
- }
- catch (TenantException e) {}
+
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant",
"sdfsdfd");
+ Assert.assertTrue("Tenant with the same id could be created
twice", false);
+ }
+ catch (TenantException e) {}
- tenantService.deleteTenant(tenant);
+ tenantService.deleteTenant(tenant);
- Assert.assertTrue(tenantService.getAllTenants().length ==
tenantCount);
+ Assert.assertTrue(tenantService.getAllTenants().length == tenantCount);
- Tenant tenant1 =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant.1",
"TEST 1");
- Tenant tenant2 =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant.2",
"TEST 2");
- Tenant tenant3 =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant.3",
"TEST 3");
- tenant1.getProperties().put("hostname", "localhost");
- tenant2.getProperties().put("hostname", "localhost");
- tenant3.getProperties().put("hostname", "amdatu.org");
- tenantService.updateTenant(tenant1);
- tenantService.updateTenant(tenant2);
- tenantService.updateTenant(tenant3);
-
- Map<String, String> filter = new HashMap<String, String>();
- filter.put("hostname", "localhost");
- Assert.assertTrue(tenantService.getTenants(filter).length == 2);
-
- filter.put("hostname", "amdatu.org");
- Assert.assertTrue(tenantService.getTenants(filter).length == 1);
-
- tenantService.deleteTenant(tenant1);
- tenantService.deleteTenant(tenant2);
- tenantService.deleteTenant(tenant3);
-
- // What happens if I remove a tenant that was already removed?
- try {
- tenantService.deleteTenant(tenant);
- Assert.assertTrue("Tenant with the same id could be deleted
twice", false);
- }
- catch (TenantException e) {}
+ Tenant tenant1 =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant.1",
"TEST 1");
+ Tenant tenant2 =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant.2",
"TEST 2");
+ Tenant tenant3 =
tenantService.createTentant("org.amdatu.test.integration.tests.testtenant.3",
"TEST 3");
+ tenant1.getProperties().put("hostname", "localhost");
+ tenant2.getProperties().put("hostname", "localhost");
+ tenant3.getProperties().put("hostname", "amdatu.org");
+ tenantService.updateTenant(tenant1);
+ tenantService.updateTenant(tenant2);
+ tenantService.updateTenant(tenant3);
+
+ Map<String, String> filter = new HashMap<String, String>();
+ filter.put("hostname", "localhost");
+ Assert.assertTrue(tenantService.getTenants(filter).length == 2);
+
+ filter.put("hostname", "amdatu.org");
+ Assert.assertTrue(tenantService.getTenants(filter).length == 1);
+
+ tenantService.deleteTenant(tenant1);
+ tenantService.deleteTenant(tenant2);
+ tenantService.deleteTenant(tenant3);
+ // What happens if I remove a tenant that was already removed?
+ try {
+ tenantService.deleteTenant(tenant);
+ Assert.assertTrue("Tenant with the same id could be deleted
twice", false);
}
- catch (TenantException e) {
- Assert.fail(TEST_PREFIX + "An error has occurred: " +
e.toString());
- e.printStackTrace();
- }
+ catch (TenantException e) {}
+
}
}
Modified:
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
==============================================================================
---
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
(original)
+++
trunk/integration-tests/src/test/java/org/amdatu/test/integration/tests/UserAdminStoreTest.java
Thu Oct 21 15:48:54 2010
@@ -16,8 +16,6 @@
*/
package org.amdatu.test.integration.tests;
-import java.io.UnsupportedEncodingException;
-
import junit.framework.Assert;
import org.amdatu.test.integration.IntegrationTestRunner;
@@ -28,7 +26,6 @@
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
import org.osgi.service.useradmin.Group;
import org.osgi.service.useradmin.Role;
import org.osgi.service.useradmin.User;
@@ -52,126 +49,116 @@
}
@Test
- public void testAdminStore() {
+ public void testAdminStore() throws Exception {
super.runTest("User Admin Store");
}
@SuppressWarnings("unchecked")
- public void run() {
+ public void run() throws Exception {
m_userAdmin = getService(UserAdmin.class);
- try {
- // Start the test, first remove all existing roles
- Role[] allRoles = m_userAdmin.getRoles(null);
- if (allRoles != null) {
- for (Role role : allRoles) {
- String roleName = role.getName();
- m_userAdmin.removeRole(roleName);
- Assert.assertTrue("Role '" + roleName + "' removed but
still returned", m_userAdmin
- .getRole(roleName) == null);
- }
+ // Start the test, first remove all existing roles
+ Role[] allRoles = m_userAdmin.getRoles(null);
+ if (allRoles != null) {
+ for (Role role : allRoles) {
+ String roleName = role.getName();
+ m_userAdmin.removeRole(roleName);
+ Assert.assertTrue("Role '" + roleName + "' removed but still
returned", m_userAdmin
+ .getRole(roleName) == null);
}
+ }
- // Test if all roles have been removed
- Assert.assertTrue("All roles were removed, but getRoles() still
returns roles",
- m_userAdmin.getRoles(null) == null
- || m_userAdmin.getRoles(null).length == 0);
-
- // Create three test users and set the credentials
- User adminUser = (User)
m_userAdmin.createRole("TestAdministrator", Role.USER);
- User editorUser = (User) m_userAdmin.createRole("TestEditor",
Role.USER);
- User guestUser = (User) m_userAdmin.createRole("TestGuest",
Role.USER);
-
- Assert.assertTrue("All users were removed, but still creating a
user failed since it already exists",
- adminUser != null && editorUser != null && guestUser != null);
- adminUser.getCredentials().put("password", "adminpasswd");
- editorUser.getCredentials().put("password", "editorpasswd");
- guestUser.getCredentials().put("password", "guestpasswd");
-
- // Now see if we can find these users from credentials
- Assert.assertTrue("TestAdmin user could not be found",
- m_userAdmin.getUser("name", "TestAdministrator") != null);
- Assert.assertTrue("TestEditor user could not be found",
m_userAdmin.getUser("name", "TestEditor") != null);
- Assert.assertTrue("TestGuest user could not be found",
m_userAdmin.getUser("name", "TestGuest") != null);
-
- // Set user properties of admin
- adminUser.getProperties().put("firstName", "John".getBytes());
- adminUser.getProperties().put("lastName", "Doe".getBytes());
-
- // And check if they were set correctly
- byte[] firstName =
- (byte[]) m_userAdmin.getUser("name",
"TestAdministrator").getProperties().get("firstName");
- Assert.assertTrue("firstName not properly set", new
String(firstName, "UTF-8").equals("John"));
- byte[] lastName = (byte[]) m_userAdmin.getUser("name",
"TestAdministrator").getProperties().get("lastName");
- Assert.assertTrue("lastName not properly set", new
String(lastName, "UTF-8").equals("Doe"));
-
- // Remove last name
- adminUser.getProperties().remove("lastName");
- Assert.assertTrue("lastName not properly removed from property
set", m_userAdmin.getUser("name",
- "TestAdministrator")
- .getProperties().get("lastName") == null);
-
- // Now create "Administrator", "Editor" and "Guest" group and do
some assignments
- Group adminGroup = (Group)
m_userAdmin.createRole("TestAdminUsers", Role.GROUP);
- Group editorGroup = (Group)
m_userAdmin.createRole("TestEditUsers", Role.GROUP);
- Group guestGroup = (Group)
m_userAdmin.createRole("TestGuestUsers", Role.GROUP);
- adminGroup.addMember(adminUser);
- adminGroup.addRequiredMember(adminUser);
-
- // Excessive test of TestEditUsers group since this failed before
- assertBasicMemberCount("TestEditUsers", 0);
- assertRequiredMemberCount("TestEditUsers", 0);
- editorGroup.addMember(adminUser);
- assertBasicMemberCount("TestEditUsers", 1);
- assertRequiredMemberCount("TestEditUsers", 0);
- editorGroup.addMember(editorUser);
- assertBasicMemberCount("TestEditUsers", 2);
- assertRequiredMemberCount("TestEditUsers", 0);
- editorGroup.addRequiredMember(adminUser);
- assertBasicMemberCount("TestEditUsers", 2);
- assertRequiredMemberCount("TestEditUsers", 1);
- editorGroup.addRequiredMember(editorUser);
- assertBasicMemberCount("TestEditUsers", 2);
- assertRequiredMemberCount("TestEditUsers", 2);
-
- guestGroup.addMember(adminUser);
- guestGroup.addMember(editorUser);
- guestGroup.addMember(guestUser);
-
- assertBasicMemberCount("TestAdminUsers", 1);
- assertRequiredMemberCount("TestAdminUsers", 1);
- assertBasicMemberCount("TestEditUsers", 2);
- assertRequiredMemberCount("TestEditUsers", 2);
- assertBasicMemberCount("TestGuestUsers", 3);
- assertRequiredMemberCount("TestGuestUsers", 0);
-
- // Now remove some members
- guestGroup.removeMember(adminUser);
- assertBasicMemberCount("TestGuestUsers", 2);
-
- // Remove the editor user, is it removed from the admin group?
- m_userAdmin.removeRole("TestEditor");
- Assert.assertTrue("TestEditor should have been removed",
m_userAdmin.getRole("TestEditor") == null);
-
- // Finally, remove all test users and groups
- allRoles = m_userAdmin.getRoles(null);
- if (allRoles != null) {
- for (Role role : allRoles) {
- String roleName = role.getName();
- m_userAdmin.removeRole(roleName);
- Assert.assertTrue("Role '" + roleName + "' removed but
still returned", m_userAdmin
- .getRole(roleName) == null);
- }
+ // Test if all roles have been removed
+ Assert.assertTrue("All roles were removed, but getRoles() still
returns roles",
+ m_userAdmin.getRoles(null) == null
+ || m_userAdmin.getRoles(null).length == 0);
+
+ // Create three test users and set the credentials
+ User adminUser = (User) m_userAdmin.createRole("TestAdministrator",
Role.USER);
+ User editorUser = (User) m_userAdmin.createRole("TestEditor",
Role.USER);
+ User guestUser = (User) m_userAdmin.createRole("TestGuest", Role.USER);
+
+ Assert.assertTrue("All users were removed, but still creating a user
failed since it already exists",
+ adminUser != null && editorUser != null && guestUser != null);
+ adminUser.getCredentials().put("password", "adminpasswd");
+ editorUser.getCredentials().put("password", "editorpasswd");
+ guestUser.getCredentials().put("password", "guestpasswd");
+
+ // Now see if we can find these users from credentials
+ Assert.assertTrue("TestAdmin user could not be found",
+ m_userAdmin.getUser("name", "TestAdministrator") != null);
+ Assert.assertTrue("TestEditor user could not be found",
m_userAdmin.getUser("name", "TestEditor") != null);
+ Assert.assertTrue("TestGuest user could not be found",
m_userAdmin.getUser("name", "TestGuest") != null);
+
+ // Set user properties of admin
+ adminUser.getProperties().put("firstName", "John".getBytes());
+ adminUser.getProperties().put("lastName", "Doe".getBytes());
+
+ // And check if they were set correctly
+ byte[] firstName =
+ (byte[]) m_userAdmin.getUser("name",
"TestAdministrator").getProperties().get("firstName");
+ Assert.assertTrue("firstName not properly set", new String(firstName,
"UTF-8").equals("John"));
+ byte[] lastName = (byte[]) m_userAdmin.getUser("name",
"TestAdministrator").getProperties().get("lastName");
+ Assert.assertTrue("lastName not properly set", new String(lastName,
"UTF-8").equals("Doe"));
+
+ // Remove last name
+ adminUser.getProperties().remove("lastName");
+ Assert.assertTrue("lastName not properly removed from property set",
m_userAdmin.getUser("name",
+ "TestAdministrator")
+ .getProperties().get("lastName") == null);
+
+ // Now create "Administrator", "Editor" and "Guest" group and do some
assignments
+ Group adminGroup = (Group) m_userAdmin.createRole("TestAdminUsers",
Role.GROUP);
+ Group editorGroup = (Group) m_userAdmin.createRole("TestEditUsers",
Role.GROUP);
+ Group guestGroup = (Group) m_userAdmin.createRole("TestGuestUsers",
Role.GROUP);
+ adminGroup.addMember(adminUser);
+ adminGroup.addRequiredMember(adminUser);
+
+ // Excessive test of TestEditUsers group since this failed before
+ assertBasicMemberCount("TestEditUsers", 0);
+ assertRequiredMemberCount("TestEditUsers", 0);
+ editorGroup.addMember(adminUser);
+ assertBasicMemberCount("TestEditUsers", 1);
+ assertRequiredMemberCount("TestEditUsers", 0);
+ editorGroup.addMember(editorUser);
+ assertBasicMemberCount("TestEditUsers", 2);
+ assertRequiredMemberCount("TestEditUsers", 0);
+ editorGroup.addRequiredMember(adminUser);
+ assertBasicMemberCount("TestEditUsers", 2);
+ assertRequiredMemberCount("TestEditUsers", 1);
+ editorGroup.addRequiredMember(editorUser);
+ assertBasicMemberCount("TestEditUsers", 2);
+ assertRequiredMemberCount("TestEditUsers", 2);
+
+ guestGroup.addMember(adminUser);
+ guestGroup.addMember(editorUser);
+ guestGroup.addMember(guestUser);
+
+ assertBasicMemberCount("TestAdminUsers", 1);
+ assertRequiredMemberCount("TestAdminUsers", 1);
+ assertBasicMemberCount("TestEditUsers", 2);
+ assertRequiredMemberCount("TestEditUsers", 2);
+ assertBasicMemberCount("TestGuestUsers", 3);
+ assertRequiredMemberCount("TestGuestUsers", 0);
+
+ // Now remove some members
+ guestGroup.removeMember(adminUser);
+ assertBasicMemberCount("TestGuestUsers", 2);
+
+ // Remove the editor user, is it removed from the admin group?
+ m_userAdmin.removeRole("TestEditor");
+ Assert.assertTrue("TestEditor should have been removed",
m_userAdmin.getRole("TestEditor") == null);
+
+ // Finally, remove all test users and groups
+ allRoles = m_userAdmin.getRoles(null);
+ if (allRoles != null) {
+ for (Role role : allRoles) {
+ String roleName = role.getName();
+ m_userAdmin.removeRole(roleName);
+ Assert.assertTrue("Role '" + roleName + "' removed but still
returned", m_userAdmin
+ .getRole(roleName) == null);
}
}
- catch (InvalidSyntaxException e) {
- Assert.fail(TEST_PREFIX + "An error has occurred: " +
e.toString());
- e.printStackTrace();
- }
- catch (UnsupportedEncodingException e) {
- Assert.fail(TEST_PREFIX + "An error has occurred: " +
e.toString());
- e.printStackTrace();
- }
}
private void assertBasicMemberCount(String group, int expected) {
Modified:
trunk/platform-bundles/cassandra-application/src/main/java/org/amdatu/platform/cassandra/application/CassandraDaemonService.java
==============================================================================
---
trunk/platform-bundles/cassandra-application/src/main/java/org/amdatu/platform/cassandra/application/CassandraDaemonService.java
(original)
+++
trunk/platform-bundles/cassandra-application/src/main/java/org/amdatu/platform/cassandra/application/CassandraDaemonService.java
Thu Oct 21 15:48:54 2010
@@ -16,26 +16,41 @@
*/
package org.amdatu.platform.cassandra.application;
+import java.util.List;
+
import org.apache.cassandra.thrift.CassandraServer;
import org.apache.cassandra.thrift.InvalidRequestException;
import org.apache.cassandra.thrift.NotFoundException;
import org.apache.thrift.TException;
/**
- * This interface defines the cassandra daemon service.
+ * This interface defines the Cassandra Daemon service. It provides the Thrift
API interface
+ * class (CassandraServer) to execute Thrift queries. Furthermore it provides
system operations;
+ * CRUD operations on Keyspaces and ColumnFamily's.
*
* @author ivol
*/
public interface CassandraDaemonService {
/**
- * Returns the Cassandra server.
+ * Returns the Cassandra server which represents the Cassandra Thrift API.
*
+ * @see http://wiki.apache.org/cassandra/API
* @return the Cassandra server.
*/
CassandraServer getCassandraServer();
/**
- * Verifies if a keyspace with the specified name exists. The check is
case-sensitive.
+ * Returns a list of all available keyspaces. Note that keyspacenames are
case-sensitive
+ * in Cassandra.
+ *
+ * @return List of all keyspaces currently available in Cassandra.
+ * @throws TException In case an error occurred while retrieving keyspaces
+ */
+ List<String> getKeyspaces() throws TException;
+
+ /**
+ * Verifies if a keyspace with the specified name exists. This check is
case-sensitive
+ * since keyspaces in Cassandra are case-sensitive.
*
* @param keyspaceName Name of the keyspace to check its existence for
* @return <code>true</code> if the keyspace exists, <code>false</code>
otherwise
@@ -44,21 +59,32 @@
boolean keyspaceExists(String keyspaceName) throws TException;
/**
- * Adds a keyspace with the specified name and throws an
IllegalArgumentException if
- * the keyspace already exists.
+ * Adds a keyspace with the specified name and throws an
InvalidRequestException if
+ * a keyspace with that name already exists. Note that keyspaces in
Cassandra are
+ * case-sensitive.
*
- * @param name Name of thekeyspace to add (case-sensitive)
- * @throws InvalidRequestException In case an error occurred while adding
the keyspace
+ * @param name Name of the keyspace to add (case-sensitive)
+ * @throws InvalidRequestException In case a keyspace with the specified
name already exists.
* @throws TException In case an error occurred while adding the keyspace
*/
void addKeyspace(String name) throws InvalidRequestException, TException;
/**
+ * Returns a list of all available ColumnFamily's in the specified
keyspace. Note that
+ * ColumnFamily names and keyspace names are case-sensitive.
+ *
+ * @param keyspaceName Name of the keyspace to retrieve the ColumnFamily's
for
+ * @return List of all available ColumnFamily's in the specified keyspace.
+ * @throws NotFoundException In case the keyspace with the specified name
could not be found
+ */
+ List<String> getColumnFamilies(String keyspaceName) throws
NotFoundException;
+
+ /**
* Verifies if the specified keyspace contains a ColumnFamily with the
specified name.
- * The check is case-sensitive.
+ * The check is case-sensitive since ColumnFamily's in Cassandra are
case-sensitive.
*
* @param keyspaceName Name of the keyspace to check
- * @param columnFamilyName Name of the ColumnFamily to look for
+ * @param columnFamilyName Name of the ColumnFamily to check its existence
for
* @return <code>true</code> if the specified keyspace contains a
ColumnFamily with the
* specified name.
*/
@@ -66,22 +92,38 @@
/**
* Adds a new ColumnFamily to the specified keyspace. If a ColumnFamily
with that name already exists
- * an exception is thrown.
+ * an exception is thrown. Note that ColumnFamily's in Cassandra are
case-sensitive
*
- * @param keyspace
- * @param cfName
- * @param columnType
- * @param comparatorType
- * @param subComparatorType
- * @throws InvalidRequestException
- * @throws TException
+ * @param keyspace Name of the keyspace to add the ColumnFamily to
+ * @param cfName Name of the ColumnFamily to add
+ * @param columnType Column type of the ColumnFamily to add
+ * @param comparatorType Comparator type of the ColumnFamily to add
+ * @param subComparatorType Sub Comparator type of the ColumnFamily to add
+ * @throws InvalidRequestException In case a ColumnFamily with the
specified name already exists in
+ * the target keyspace
+ * @throws TException If an error occurred while adding the ColumnFamily
*/
void addColumnFamily(String keyspace, String cfName, String columnType,
String comparatorType,
String subComparatorType) throws InvalidRequestException, TException;
+ /**
+ * Verifies if the ColumnFamily specified by keyspace and ColumFamily name
already present in
+ * Cassandra has the same columnType, comparatorType and subComparatorType
as specified. If no
+ * ColumnFamily with the specified name exists, false is returned. Only in
case a ColumnFamily
+ * with the specified name in the specified keyspace exists with not
exactly the same columnType,
+ * comparatorType and subComparatorType true is returned.
+ *
+ * @param keyspace The keyspace to check the ColumnFamily for
+ * @param cfName Name of the ColumnFamily to check
+ * @param columnType Column type to compare the ColumnFamily with
+ * @param comparatorType Comparator type to compare the ColumnFamily with
+ * @param subComparatorType Sub comparator type to compare the
ColumnFamily with
+ * @return <code>true</code> in case a ColumnFamily with the specified
name in the specified keyspace exists with not exactly the same columnType,
+ * comparatorType and subComparatorType. <code>false</code> in all
other cases.
+ * @throws NotFoundException In case the specified keyspace could not be
found
+ * @throws InvalidRequestException In case the specified ColumnFamily
could not be found
+ * @throws TException in case an error occurred while comparing the
ColumnFamily
+ */
boolean isColumnFamilyChanged(String keyspace, String cfName, String
columnType, String comparatorType,
String subComparatorType) throws NotFoundException,
InvalidRequestException, TException;
-
- void updateColumnFamily(String keyspace, String cfName, String columnType,
String comparatorType,
- String subComparatorType) throws InvalidRequestException, TException;
}
Modified:
trunk/platform-bundles/cassandra-application/src/main/java/org/amdatu/platform/cassandra/application/service/CassandraDaemonServiceImpl.java
==============================================================================
---
trunk/platform-bundles/cassandra-application/src/main/java/org/amdatu/platform/cassandra/application/service/CassandraDaemonServiceImpl.java
(original)
+++
trunk/platform-bundles/cassandra-application/src/main/java/org/amdatu/platform/cassandra/application/service/CassandraDaemonServiceImpl.java
Thu Oct 21 15:48:54 2010
@@ -105,6 +105,15 @@
}
return false;
}
+
+ public List<String> getKeyspaces() throws TException {
+ List<String> keyspaceNames = new ArrayList<String>();
+ List<KsDef> keyspaces = m_cassandraServer.describe_keyspaces();
+ for (KsDef keyspace : keyspaces) {
+ keyspaceNames.add( keyspace.getName());
+ }
+ return keyspaceNames;
+ }
public void addKeyspace(String name) throws InvalidRequestException,
TException {
List<CfDef> empty = new ArrayList<CfDef>();
@@ -123,6 +132,16 @@
return false;
}
+ public List<String> getColumnFamilies(String keyspaceName) throws
NotFoundException {
+ List<String> cfNames = new ArrayList<String>();
+ KsDef ksDef = m_cassandraServer.describe_keyspace(keyspaceName);
+ List<CfDef> cfDefs = ksDef.getCf_defs();
+ for (CfDef cfDef : cfDefs) {
+ cfNames.add( cfDef.getName());
+ }
+ return cfNames;
+ }
+
public void addColumnFamily(String keyspace, String cfName, String
columnType, String comparatorType,
String subComparatorType) throws InvalidRequestException, TException {
if (keyspace.equals(Table.SYSTEM_TABLE)) {
@@ -156,19 +175,4 @@
}
return false;
}
-
- public void updateColumnFamily(String keyspace, String cfName, String
columnType, String comparatorType,
- String subComparatorType) throws InvalidRequestException, TException {
- CfDef cfDef = new CfDef(keyspace, cfName);
- cfDef.column_type = columnType;
- cfDef.comparator_type = comparatorType;
- cfDef.subcomparator_type = subComparatorType;
-
- // Cassandra does not support changes of column_type, comparator_type
or subcomparator_type in
- // existing ColumnFamily's. The update method is intended only for
minor changes, like
- // comment, row_cache_size, preload_row_cache and key_cache_size for
which we always use the default
- // values
- m_cassandraServer.set_keyspace(keyspace);
- m_cassandraServer.system_update_column_family(cfDef);
- }
}