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 2015/11/17 23:05:14 UTC
[19/39] usergrid git commit: Added additional test to verify that we
can delete and fix single values
Added additional test to verify that we can delete and fix single values
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/14eec4f2
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/14eec4f2
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/14eec4f2
Branch: refs/heads/1.x
Commit: 14eec4f229c988704753083a543bf2dd378d615d
Parents: 80ad870
Author: George Reyes <gr...@apache.org>
Authored: Fri Nov 6 14:22:03 2015 -0800
Committer: George Reyes <gr...@apache.org>
Committed: Fri Nov 6 14:22:03 2015 -0800
----------------------------------------------------------------------
.../usergrid/tools/UniqueIndexCleanupTest.java | 88 ++++++++++++++++++--
1 file changed, 81 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/14eec4f2/stack/tools/src/test/java/org/apache/usergrid/tools/UniqueIndexCleanupTest.java
----------------------------------------------------------------------
diff --git a/stack/tools/src/test/java/org/apache/usergrid/tools/UniqueIndexCleanupTest.java b/stack/tools/src/test/java/org/apache/usergrid/tools/UniqueIndexCleanupTest.java
index b3b7896..315cc16 100644
--- a/stack/tools/src/test/java/org/apache/usergrid/tools/UniqueIndexCleanupTest.java
+++ b/stack/tools/src/test/java/org/apache/usergrid/tools/UniqueIndexCleanupTest.java
@@ -405,6 +405,8 @@ public class UniqueIndexCleanupTest {
}
//should return null since we have duplicate alias. Will Cause index corruptions to be thrown.
+ //TODO: fix the below so that it fails everytime.
+ //50/50 chance to succeed or fail
assertNull( entityManager
.get( entityManager.getAlias( applicationInfo.getId(), collectionName, username ).getUuid() ) );
@@ -421,13 +423,85 @@ public class UniqueIndexCleanupTest {
}
- private static int getFileCount( File exportDir, final String ext ) {
- return exportDir.listFiles( new FileFilter() {
- @Override
- public boolean accept( File pathname ) {
- return pathname.getAbsolutePath().endsWith( "." + ext );
- }
- } ).length;
+ @Test
+ public void testRepairOfOnlyOneOfTwoColumnsWhilePointingAtSingleValue() throws Exception{
+ String rand = RandomStringUtils.randomAlphanumeric( 10 );
+
+ String orgName = "org_" + rand;
+ String appName = "app_" +rand;
+ String username = "username_" + rand;
+ String adminUsername = "admin_"+rand;
+ String email = username+"@derp.com";
+ String password = username;
+
+ String collectionName = "users";
+
+
+ OrganizationOwnerInfo organizationOwnerInfo = setup.getMgmtSvc().createOwnerAndOrganization( orgName,adminUsername,adminUsername,email,password );
+
+ ApplicationInfo applicationInfo = setup.getMgmtSvc().createApplication( organizationOwnerInfo.getOrganization().getUuid(),appName );
+
+ EntityManager entityManager = setup.getEmf().getEntityManager( applicationInfo.getId() );
+
+ Map<String,Object> userInfo = new HashMap<String, Object>( );
+ userInfo.put( "username",username );
+
+ //Entity entityToBeCorrupted = entityManager.create( collectionName,userInfo );
+
+ CassandraService cass = setup.getCassSvc();
+
+ Object key = CassandraPersistenceUtils.key( applicationInfo.getId(), collectionName, "username", username );
+
+ Keyspace ko = cass.getApplicationKeyspace( applicationInfo.getId() );
+ Mutator<ByteBuffer> m = createMutator( ko, be );
+
+ //create a new column
+ Entity validCoexistingEntity = entityManager.create( collectionName, userInfo );
+
+ UUID testEntityUUID = UUIDUtils.newTimeUUID();
+ //this below calll should make the column family AND the column name for an already existing column thus adding one legit and one dummy value.
+ addInsertToMutator( m,ENTITY_UNIQUE,key, testEntityUUID,0,createTimestamp());
+
+ m.execute();
+
+ //verify that there is no corresponding entity with the uuid or alias provided
+ //verify it returns null.
+ assertNull(entityManager.get( testEntityUUID ));
+
+ //the below works but not needed for this test.
+ //assertNull( entityManager.getAlias("user",username));
+
+ //verify that we cannot recreate the entity due to duplicate unique property exception
+ Entity entityToBeCorrupted = null;
+ try {
+ entityToBeCorrupted = entityManager.create( collectionName, userInfo );
+ fail();
+ }catch(DuplicateUniquePropertyExistsException dup){
+
+ }
+ catch(Exception e){
+ fail("shouldn't throw something else i think");
+ }
+
+ //should return null since we have duplicate alias. Will Cause index corruptions to be thrown.
+ assertNull( entityManager
+ .get( entityManager.getAlias( applicationInfo.getId(), collectionName, username ).getUuid() ) );
+
+
+ //run the cleanup
+ UniqueIndexCleanup uniqueIndexCleanup = new UniqueIndexCleanup();
+ uniqueIndexCleanup.startTool( new String[] {
+ "-host", "localhost:"+ ServiceITSuite.cassandraResource.getRpcPort(),
+ "-app",applicationInfo.getId().toString(),
+ "-property","username",
+ "-value",username
+ }, false );
+
+ //verifies it works now.
+ assertNotNull( entityManager
+ .get( entityManager.getAlias( applicationInfo.getId(), collectionName, username ).getUuid() ) );
+
}
+
}