pivotal-eshu commented on code in PR #7596:
URL: https://github.com/apache/geode/pull/7596#discussion_r855680249
##########
geode-core/src/test/java/org/apache/geode/internal/cache/BucketRegionTest.java:
##########
@@ -715,4 +722,178 @@ public void
txHandleWANEventDoesNotCallHandleWANEventIfParallelWanNotEnabled() {
verify(bucketRegion, never()).handleWANEvent(event);
}
+
+ @Test
+ public void
needToWaitForColocatedBucketsBecomePrimaryReturnsTrueIfHasChildRegionAndWasNotPrimary()
{
+ BucketRegion bucketRegion =
+ spy(new BucketRegion(regionName, regionAttributes, partitionedRegion,
+ cache, internalRegionArgs, disabledClock()));
+ doReturn(true).when(bucketRegion).hasChildRegion();
+
+
assertThat(bucketRegion.needToWaitForColocatedBucketsBecomePrimary()).isTrue();
+ }
+
+ @Test
+ public void
needToWaitForColocatedBucketsBecomePrimaryReturnsFalseIfHasChildRegionAndWasPrimary()
{
+ BucketRegion bucketRegion =
+ spy(new BucketRegion(regionName, regionAttributes, partitionedRegion,
+ cache, internalRegionArgs, disabledClock()));
+ doReturn(true).when(bucketRegion).hasChildRegion();
+ bucketRegion.notPrimary = false;
+
+
assertThat(bucketRegion.needToWaitForColocatedBucketsBecomePrimary()).isFalse();
+ }
+
+ @Test
+ public void
needToWaitForColocatedBucketsBecomePrimaryReturnsFalseIfNoChildRegion() {
+ BucketRegion bucketRegion =
+ spy(new BucketRegion(regionName, regionAttributes, partitionedRegion,
+ cache, internalRegionArgs, disabledClock()));
+ doReturn(false).when(bucketRegion).hasChildRegion();
+
+
assertThat(bucketRegion.needToWaitForColocatedBucketsBecomePrimary()).isFalse();
+ }
+
+ @Test
+ public void
handleWANEventDoesNotWaitForAllChildColocatedBucketsBecomePrimaryIfNoNeedToWait()
{
+ BucketRegion bucketRegion =
+ spy(new BucketRegion(regionName, regionAttributes, partitionedRegion,
+ cache, internalRegionArgs, disabledClock()));
+ when(bucketAdvisor.isPrimary()).thenReturn(true);
+
doReturn(false).when(bucketRegion).needToWaitForColocatedBucketsBecomePrimary();
+
+ when(partitionedRegion.getTotalNumberOfBuckets()).thenReturn(4);
+ doReturn(0).when(bucketRegion).getId();
+
+ bucketRegion.handleWANEvent(event);
+
+ verify(bucketRegion,
never()).waitForAllChildColocatedBucketsBecomePrimary();
+ verify(event).setTailKey(4L);
+ }
+
+ @Test
+ public void
handleWANEventWaitsForAllChildColocatedBucketsBecomePrimaryIfWasNotPrimary() {
+ BucketRegion bucketRegion =
+ spy(new BucketRegion(regionName, regionAttributes, partitionedRegion,
+ cache, internalRegionArgs, disabledClock()));
+ when(bucketAdvisor.isPrimary()).thenReturn(true);
+ doReturn(true).when(bucketRegion).hasChildRegion();
+
doNothing().when(bucketRegion).waitForAllChildColocatedBucketsBecomePrimary();
+ when(partitionedRegion.getTotalNumberOfBuckets()).thenReturn(4);
+ doReturn(0).when(bucketRegion).getId();
+
+ bucketRegion.handleWANEvent(event);
+
+ verify(bucketRegion).waitForAllChildColocatedBucketsBecomePrimary();
+ verify(event).setTailKey(4L);
+ }
+
+ @Test
+ public void handleWANEventSetNotPrimaryIfWasPrimaryAndNoLongerAPrimary() {
+ BucketRegion bucketRegion =
+ spy(new BucketRegion(regionName, regionAttributes, partitionedRegion,
+ cache, internalRegionArgs, disabledClock()));
+ when(bucketAdvisor.isPrimary()).thenReturn(false);
+ bucketRegion.notPrimary = false;
+
+ bucketRegion.handleWANEvent(event);
+
+ verify(bucketRegion).setNotPrimaryIfNecessary();
+ assertThat(bucketRegion.notPrimary).isTrue();
+ assertThat(bucketRegion.allChildBucketsBecomePrimary).isFalse();
+ }
+
+ @Test
+ public void handleWANEventDoesNotSetNotPrimaryIfWasNotPrimary() {
+ BucketRegion bucketRegion =
+ spy(new BucketRegion(regionName, regionAttributes, partitionedRegion,
+ cache, internalRegionArgs, disabledClock()));
+ when(bucketAdvisor.isPrimary()).thenReturn(false);
+ bucketRegion.notPrimary = true;
+
+ bucketRegion.handleWANEvent(event);
+
+ verify(bucketRegion, never()).setNotPrimaryIfNecessary();
+ }
+
+ @Test
+ public void onlyOneThreadWillExecuteCheckIfAllChildBucketsBecomePrimary()
throws Exception {
+ BucketRegion bucketRegion =
+ spy(new BucketRegion(regionName, regionAttributes, partitionedRegion,
+ cache, internalRegionArgs, disabledClock()));
+
doNothing().when(bucketRegion).executeCheckIfAllChildBucketsBecomePrimary();
+
+ Future<?> future =
executor.submit(bucketRegion::waitForAllChildColocatedBucketsBecomePrimary);
+ Future<?> future2 =
executor.submit(bucketRegion::waitForAllChildColocatedBucketsBecomePrimary);
+
+ future.get();
+ future2.get();
Review Comment:
Not sure if we definitely can hit the race issue in the unit test. Is there
any suggestion for this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]