Skip to content

Commit

Permalink
Made unit test more stable
Browse files Browse the repository at this point in the history
  • Loading branch information
jnidzwetzki committed Oct 24, 2018
1 parent 2d99ba2 commit 368bed8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.bboxdb.distribution.partitioner;

import java.util.List;
import java.util.function.Predicate;

import org.bboxdb.distribution.DistributionGroupConfigurationCache;
import org.bboxdb.distribution.TupleStoreConfigurationCache;
Expand All @@ -27,6 +28,7 @@
import org.bboxdb.distribution.region.DistributionRegionCallback;
import org.bboxdb.distribution.region.DistributionRegionIdMapper;
import org.bboxdb.distribution.region.DistributionRegionSyncer;
import org.bboxdb.distribution.region.DistributionRegionSyncerHelper;
import org.bboxdb.distribution.zookeeper.DistributionGroupAdapter;
import org.bboxdb.distribution.zookeeper.DistributionRegionAdapter;
import org.bboxdb.distribution.zookeeper.ZookeeperClient;
Expand Down Expand Up @@ -220,4 +222,16 @@ public void splitFailed(final DistributionRegion sourceRegion, final List<Distri
public DistributionRegionSyncer getDistributionRegionSyncer() {
return distributionRegionSyncer;
}

/**
* Wait until the node state is
* @param region
* @param state
* @throws InterruptedException
*/
@VisibleForTesting
public void waitUntilNodeStateIs(final DistributionRegion region, final DistributionRegionState state) throws InterruptedException {
final Predicate<DistributionRegion> predicate = (r) -> r.getState() == state;
DistributionRegionSyncerHelper.waitForPredicate(predicate, region, distributionRegionSyncer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,6 @@ public void waitForSplitCompleteZookeeperCallback(final DistributionRegion regio
final Predicate<DistributionRegion> predicate = (r) -> isSplitForNodeComplete(r, noOfChildren);
DistributionRegionSyncerHelper.waitForPredicate(predicate, regionToSplit, distributionRegionSyncer);
}

/**
* Wait until the node state is
* @param region
* @param state
* @throws InterruptedException
*/
@VisibleForTesting
public void waitUntilNodeStateIs(final DistributionRegion region, final DistributionRegionState state) throws InterruptedException {
final Predicate<DistributionRegion> predicate = (r) -> r.getState() == state;
DistributionRegionSyncerHelper.waitForPredicate(predicate, region, distributionRegionSyncer);
}

/**
* Is the split for the given node complete?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ public void testIsSplitable() throws ZookeeperException, ZookeeperNotFoundExcept
* @throws BBoxDBException
* @throws ZookeeperNotFoundException
* @throws ZookeeperException
* @throws InterruptedException
*/
@Test(timeout=80000)
public void testSplitAndMergeRegion() throws BBoxDBException, ZookeeperException, ZookeeperNotFoundException {
public void testSplitAndMergeRegion() throws BBoxDBException, ZookeeperException, ZookeeperNotFoundException, InterruptedException {
final DynamicgridSpacePartitioner spacePartitioner = getSpacePartitioner();
final DistributionRegion rootElement = spacePartitioner.getRootNode();

Expand All @@ -167,7 +168,11 @@ public void testSplitAndMergeRegion() throws BBoxDBException, ZookeeperException
Assert.assertEquals(oldChildren + 2, newChilden1);

spacePartitioner.splitComplete(regionToSplit, newRegions);


for(final DistributionRegion region : newRegions) {
spacePartitioner.waitUntilNodeStateIs(region, DistributionRegionState.ACTIVE);
}

final int newChilden2 = regionToSplit.getParent().getThisAndChildRegions().size();
Assert.assertEquals(oldChildren + 1, newChilden2);

Expand Down

0 comments on commit 368bed8

Please sign in to comment.