Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
bucket tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Feldman committed Jun 11, 2015
1 parent 1cd23fc commit 9af4390
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ApplicationIndexBucketLocator{
/** /**
* Number of buckets to hash across. * Number of buckets to hash across.
*/ */
private final int[] numberOfBuckets ; private final int numberOfBuckets ;
/** /**
* How to funnel keys for buckets * How to funnel keys for buckets
*/ */
Expand All @@ -50,12 +50,10 @@ public class ApplicationIndexBucketLocator{
*/ */
private final int indexBucketSeed; private final int indexBucketSeed;


private final CoreIndexFig indexFig;


@Inject @Inject
public ApplicationIndexBucketLocator(CoreIndexFig indexFig){ public ApplicationIndexBucketLocator(CoreIndexFig indexFig){
this.indexFig = indexFig; numberOfBuckets = indexFig.getNumberOfIndexBuckets();
numberOfBuckets = new int[indexFig.getNumberOfIndexBuckets()];
mapKeyFunnel = (key, into) -> into.putString( key, StringHashUtils.UTF8 ); mapKeyFunnel = (key, into) -> into.putString( key, StringHashUtils.UTF8 );
indexBucketSeed = indexFig.getBucketSeed(); indexBucketSeed = indexFig.getBucketSeed();
bucketLocator = new ExpandingShardLocator<>(mapKeyFunnel, numberOfBuckets); bucketLocator = new ExpandingShardLocator<>(mapKeyFunnel, numberOfBuckets);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.usergrid.persistence.IndexBucketLocator; import org.apache.usergrid.persistence.IndexBucketLocator;
import org.apache.usergrid.persistence.core.astyanax.CassandraFig; import org.apache.usergrid.persistence.core.astyanax.CassandraFig;
import org.apache.usergrid.persistence.core.scope.ApplicationScope; import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.core.test.UseModules; import org.apache.usergrid.persistence.core.test.UseModules;
import org.apache.usergrid.persistence.index.IndexFig; import org.apache.usergrid.persistence.index.IndexFig;
import org.apache.usergrid.persistence.index.IndexLocationStrategy; import org.apache.usergrid.persistence.index.IndexLocationStrategy;
Expand All @@ -34,9 +35,12 @@
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;


import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


/** /**
Expand Down Expand Up @@ -80,6 +84,7 @@ public void managementNaming(){
IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(managementApplicationScope); IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(managementApplicationScope);
assertEquals(indexLocationStrategy.getIndexRootName(),managementLocationStrategy.getIndexRootName()); assertEquals(indexLocationStrategy.getIndexRootName(),managementLocationStrategy.getIndexRootName());
assertEquals(indexLocationStrategy.getIndexRootName(),indexProcessorFig.getManagementAppIndexName()); assertEquals(indexLocationStrategy.getIndexRootName(),indexProcessorFig.getManagementAppIndexName());
assertEquals(indexLocationStrategy.getIndexRootName(), indexLocationStrategy.getIndexBucketName());


} }
@Test @Test
Expand All @@ -93,6 +98,25 @@ public void applicationNaming(){
assertTrue(indexLocationStrategy.getAlias().getWriteAlias().contains(applicationScope.getApplication().getUuid().toString().toLowerCase())); assertTrue(indexLocationStrategy.getAlias().getWriteAlias().contains(applicationScope.getApplication().getUuid().toString().toLowerCase()));
assertTrue(indexLocationStrategy.getAlias().getWriteAlias().contains("write")); assertTrue(indexLocationStrategy.getAlias().getWriteAlias().contains("write"));
assertTrue(indexLocationStrategy.getAlias().getReadAlias().contains("read")); assertTrue(indexLocationStrategy.getAlias().getReadAlias().contains("read"));
Set<String> names = new HashSet<>();
for(int i=0;i<10;i++){
IndexLocationStrategy indexLocationStrategyBucket = new ApplicationIndexLocationStrategy(cassandraFig,indexFig,applicationScope, new ApplicationIndexBucketLocator(indexProcessorFig));
names.add(indexLocationStrategyBucket.getIndexBucketName());
}
//always hashes to same bucket
assertTrue(names.size()==1);
names = new HashSet<>();
for(int i=0;i<10;i++){
IndexLocationStrategy indexLocationStrategyBucket =
new ApplicationIndexLocationStrategy(
cassandraFig,
indexFig,
new ApplicationScopeImpl(CpNamingUtils.generateApplicationId(UUID.randomUUID())),
new ApplicationIndexBucketLocator(indexProcessorFig));
names.add(indexLocationStrategyBucket.getIndexBucketName());
}
//always hashes to diff't bucket
assertTrue(names.size()>1);


} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public void initialize() {
} }
} }


/**
* if there are aliases then we must have an index...weak knowledge
* @return
*/
private boolean shouldInitialize() { private boolean shouldInitialize() {
String[] reads = getIndexes(); String[] reads = getIndexes();
return reads.length==0; return reads.length==0;
Expand All @@ -175,7 +179,7 @@ public void addIndex(final Optional<String> indexNameOverride,
final String writeConsistency final String writeConsistency
) { ) {
try { try {
//get index name with suffix attached //get index name with bucket attached
final String indexName = indexNameOverride.or( indexLocationStrategy.getIndexBucketName() ) ; final String indexName = indexNameOverride.or( indexLocationStrategy.getIndexBucketName() ) ;


//Create index //Create index
Expand Down Expand Up @@ -269,15 +273,6 @@ public String[] getIndexes(final AliasType aliasType) {
return aliasCache.getIndexes(alias, aliasType); return aliasCache.getIndexes(alias, aliasType);
} }


/**
* Get our index info from ES, but clear our cache first
* @param aliasType
* @return
*/
public String[] getIndexesFromEs(final AliasType aliasType){
aliasCache.invalidate(alias);
return getIndexes(aliasType);
}


/** /**
* Tests writing a document to a new index to ensure it's working correctly. See this post: * Tests writing a document to a new index to ensure it's working correctly. See this post:
Expand Down

0 comments on commit 9af4390

Please sign in to comment.