[ 
https://issues.apache.org/jira/browse/GEODE-8692?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17229415#comment-17229415
 ] 

ASF GitHub Bot commented on GEODE-8692:
---------------------------------------

DonalEvans commented on a change in pull request #5722:
URL: https://github.com/apache/geode/pull/5722#discussion_r520742186



##########
File path: 
geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/RegionAdvisorJUnitTest.java
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.partitioned;
+
+import static 
org.apache.geode.distributed.internal.DistributionAdvisor.ILLEGAL_SERIAL;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.cache.PartitionAttributes;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.distributed.internal.DistributionManager;
+import 
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.BucketAdvisor;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.ProxyBucketRegion;
+
+public class RegionAdvisorJUnitTest {
+
+  private PartitionedRegion partitionedRegion;
+  private RegionAdvisor regionAdvisor;
+  private final int[] serials = new int[] {ILLEGAL_SERIAL, ILLEGAL_SERIAL, 
ILLEGAL_SERIAL};
+
+  @Before
+  public void setUp() throws Exception {
+    partitionedRegion = mock(PartitionedRegion.class);
+    regionAdvisor = new RegionAdvisor(partitionedRegion);
+  }
+
+  @Test
+  public void 
getBucketSerials_shouldReturnAnArrayOfIllegalSerials_whenBucketsAreNull() {
+    RegionAttributes regionAttributes = mock(RegionAttributes.class);
+    PartitionAttributes partitionAttributes = mock(PartitionAttributes.class);
+    when(partitionedRegion.getAttributes()).thenReturn(regionAttributes);
+    
when(regionAttributes.getPartitionAttributes()).thenReturn(partitionAttributes);
+    when(partitionAttributes.getTotalNumBuckets()).thenReturn(3);
+
+    assertThat(regionAdvisor.getBucketSerials()).containsExactly(serials);
+  }
+
+  @Test
+  public void 
processProfilesQueuedDuringInitialization_shouldNotThrowIndexOutOfBoundsException()
 {

Review comment:
       Two of the variable names in this test, `qbp` and `pbr` could be a bit 
more descriptive. I don't think there's anything wrong with long variable 
names, providing it's providing extra clarity.

##########
File path: 
geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/RegionAdvisorJUnitTest.java
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.partitioned;
+
+import static 
org.apache.geode.distributed.internal.DistributionAdvisor.ILLEGAL_SERIAL;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.cache.PartitionAttributes;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.distributed.internal.DistributionManager;
+import 
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.BucketAdvisor;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.ProxyBucketRegion;
+
+public class RegionAdvisorJUnitTest {
+
+  private PartitionedRegion partitionedRegion;
+  private RegionAdvisor regionAdvisor;
+  private final int[] serials = new int[] {ILLEGAL_SERIAL, ILLEGAL_SERIAL, 
ILLEGAL_SERIAL};
+
+  @Before
+  public void setUp() throws Exception {
+    partitionedRegion = mock(PartitionedRegion.class);
+    regionAdvisor = new RegionAdvisor(partitionedRegion);
+  }
+
+  @Test
+  public void 
getBucketSerials_shouldReturnAnArrayOfIllegalSerials_whenBucketsAreNull() {
+    RegionAttributes regionAttributes = mock(RegionAttributes.class);
+    PartitionAttributes partitionAttributes = mock(PartitionAttributes.class);
+    when(partitionedRegion.getAttributes()).thenReturn(regionAttributes);
+    
when(regionAttributes.getPartitionAttributes()).thenReturn(partitionAttributes);
+    when(partitionAttributes.getTotalNumBuckets()).thenReturn(3);
+
+    assertThat(regionAdvisor.getBucketSerials()).containsExactly(serials);
+  }
+
+  @Test
+  public void 
processProfilesQueuedDuringInitialization_shouldNotThrowIndexOutOfBoundsException()
 {
+    RegionAdvisor.QueuedBucketProfile qbp =
+        new 
RegionAdvisor.QueuedBucketProfile(mock(InternalDistributedMember.class), 
serials, true);
+    DistributionManager distributionManager = mock(DistributionManager.class);
+    
when(regionAdvisor.getDistributionManager()).thenReturn(distributionManager);
+    when(distributionManager.isCurrentMember(any())).thenReturn(true);
+    regionAdvisor.preInitQueue.add(qbp);
+
+    ProxyBucketRegion pbr = mock(ProxyBucketRegion.class);
+    when(pbr.getBucketAdvisor()).thenReturn(mock(BucketAdvisor.class));
+    regionAdvisor.buckets = new ProxyBucketRegion[] {pbr, pbr, pbr};
+
+    regionAdvisor.processProfilesQueuedDuringInitialization();

Review comment:
       Might it be worth adding a check to verify that 
`ProxyBucketRegion.removeIdWithSerial()` is never called for the contents of 
`regionAdvisor.buckets` since the serial is always `ILLEGAL_SERIAL`? Or would 
that be outside the scope of this test?

##########
File path: 
geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/RegionAdvisorJUnitTest.java
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache.partitioned;
+
+import static 
org.apache.geode.distributed.internal.DistributionAdvisor.ILLEGAL_SERIAL;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.geode.cache.PartitionAttributes;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.distributed.internal.DistributionManager;
+import 
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.cache.BucketAdvisor;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.ProxyBucketRegion;
+
+public class RegionAdvisorJUnitTest {
+
+  private PartitionedRegion partitionedRegion;
+  private RegionAdvisor regionAdvisor;
+  private final int[] serials = new int[] {ILLEGAL_SERIAL, ILLEGAL_SERIAL, 
ILLEGAL_SERIAL};
+
+  @Before
+  public void setUp() throws Exception {
+    partitionedRegion = mock(PartitionedRegion.class);
+    regionAdvisor = new RegionAdvisor(partitionedRegion);
+  }
+
+  @Test
+  public void 
getBucketSerials_shouldReturnAnArrayOfIllegalSerials_whenBucketsAreNull() {
+    RegionAttributes regionAttributes = mock(RegionAttributes.class);
+    PartitionAttributes partitionAttributes = mock(PartitionAttributes.class);
+    when(partitionedRegion.getAttributes()).thenReturn(regionAttributes);
+    
when(regionAttributes.getPartitionAttributes()).thenReturn(partitionAttributes);
+    when(partitionAttributes.getTotalNumBuckets()).thenReturn(3);

Review comment:
       Could this hardcoded 3 be replaced with `serials.length` to ensure that 
the test doesn't fail if someone modifies the size of `serials`?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> ArrayIndexOutOfBoundsException may be thrown in 
> RegionAdvisor.processProfilesQueuedDuringInitialization
> -------------------------------------------------------------------------------------------------------
>
>                 Key: GEODE-8692
>                 URL: https://issues.apache.org/jira/browse/GEODE-8692
>             Project: Geode
>          Issue Type: Bug
>            Reporter: Sarah Abbey
>            Assignee: Sarah Abbey
>            Priority: Minor
>              Labels: pull-request-available
>
> If {{RegionAdvisor.buckets == null}} at the time the value of {{serials}} is 
> generated, an {{ArrayIndexOutOfBoundsException}} may be thrown in 
> {{RegionAdvisor.processProfilesQueuedDuringInitialization}} if buckets have 
> been initialized at that point.
> Code where {{ArrayIndexOutOfBoundsException}} might be thrown in 
> {{RegionAdvisor.processProfilesQueuedDuringInitialization():}}
> {code:java}
> for (int i = 0; i < buckets.length; i++) {
>   BucketAdvisor ba = buckets[i].getBucketAdvisor();
>   int serial = qbp.serials[i]; <<< Exception thrown here
>   if (serial != ILLEGAL_SERIAL) {
>     ba.removeIdWithSerial(qbp.memberId, serial, qbp.destroyed);
>   }
> }
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to