This is an automated email from the ASF dual-hosted git repository.
klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 11747fa GEODE-6416: Fix GetRegionsFunctionTest and
InternalDistributedSystemTest
11747fa is described below
commit 11747fa8f952e1c83ef32022b87789da6a6d7f41
Author: Kirk Lund <[email protected]>
AuthorDate: Fri Feb 15 12:00:26 2019 -0800
GEODE-6416: Fix GetRegionsFunctionTest and InternalDistributedSystemTest
InternalDistributedSystemTest started failing in CI because
GetRegionsFunctionTest started executing before it.
GetRegionsFunctionTest sets a system property without
cleaning up after itself.
---
.../internal/InternalDistributedSystemTest.java | 13 +--
...ava => GetRegionsFunctionCacheFactoryTest.java} | 10 +-
.../cli/functions/GetRegionsFunctionJUnitTest.java | 108 -------------------
.../cli/functions/GetRegionsFunctionTest.java | 115 +++++++++++++--------
4 files changed, 85 insertions(+), 161 deletions(-)
diff --git
a/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalDistributedSystemTest.java
b/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalDistributedSystemTest.java
index ab0f08a..b800923 100644
---
a/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalDistributedSystemTest.java
+++
b/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalDistributedSystemTest.java
@@ -46,10 +46,10 @@ public class InternalDistributedSystemTest {
private static final String STATISTICS_TEXT_ID = "statistics-text-id";
private static final long STATISTICS_NUMERIC_ID = 2349;
- @Mock
+ @Mock(name = "autowiredStatisticsManagerFactory")
public StatisticsManagerFactory statisticsManagerFactory;
- @Mock
+ @Mock(name = "autowiredStatisticsManager")
public StatisticsManager statisticsManager;
private InternalDistributedSystem internalDistributedSystem;
@@ -65,11 +65,12 @@ public class InternalDistributedSystemTest {
@Test
public void createsStatisticsManagerViaFactory() {
- boolean defaultStatsDisabled = false;
- String defaultMemberName = "";
- StatisticsManager statisticsManagerCreatedByFactory =
mock(StatisticsManager.class);
+ StatisticsManagerFactory statisticsManagerFactory =
+ mock(StatisticsManagerFactory.class, "statisticsManagerFactory");
+ StatisticsManager statisticsManagerCreatedByFactory =
+ mock(StatisticsManager.class, "statisticsManagerCreatedByFactory");
when(statisticsManagerFactory
- .create(eq(defaultMemberName), anyLong(), eq(defaultStatsDisabled)))
+ .create(any(), anyLong(), eq(false)))
.thenReturn(statisticsManagerCreatedByFactory);
InternalDistributedSystem result =
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionCacheFactoryTest.java
similarity index 89%
copy from
geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionTest.java
copy to
geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionCacheFactoryTest.java
index 82d1ef8..f9c1a1c 100644
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionTest.java
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionCacheFactoryTest.java
@@ -31,14 +31,14 @@ import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.ResultSender;
-public class GetRegionsFunctionTest {
+public class GetRegionsFunctionCacheFactoryTest {
private enum STATE {
INITIAL, BLOCKING, FINISHED
};
- private static GetRegionsFunctionTest.STATE lockingThreadState =
- GetRegionsFunctionTest.STATE.INITIAL;
+ private static GetRegionsFunctionCacheFactoryTest.STATE lockingThreadState =
+ GetRegionsFunctionCacheFactoryTest.STATE.INITIAL;
private static AtomicBoolean lockAquired = new AtomicBoolean(false);
private static AtomicBoolean functionExecuted = new AtomicBoolean(false);
@@ -57,12 +57,12 @@ public class GetRegionsFunctionTest {
new Thread(() -> {
synchronized (CacheFactory.class) {
lockAquired.set(true);
- lockingThreadState = GetRegionsFunctionTest.STATE.BLOCKING;
+ lockingThreadState = GetRegionsFunctionCacheFactoryTest.STATE.BLOCKING;
try {
await().untilTrue(functionExecuted);
} catch (ConditionTimeoutException e) {
e.printStackTrace();
- lockingThreadState = GetRegionsFunctionTest.STATE.FINISHED;
+ lockingThreadState =
GetRegionsFunctionCacheFactoryTest.STATE.FINISHED;
}
}
}).start();
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionJUnitTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionJUnitTest.java
deleted file mode 100644
index e6b8bcc..0000000
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionJUnitTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.management.internal.cli.functions;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-import org.apache.geode.CancelCriterion;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.execute.FunctionContext;
-import org.apache.geode.cache.execute.ResultSender;
-import org.apache.geode.distributed.internal.DistributionConfig;
-import org.apache.geode.distributed.internal.InternalDistributedSystem;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.internal.cache.LocalRegion;
-import org.apache.geode.internal.cache.control.InternalResourceManager;
-
-public class GetRegionsFunctionJUnitTest {
-
- TestResultSender testResultSender = new TestResultSender();
- Set<Region<?, ?>> regions = new HashSet<>();
- Set<Region<?, ?>> subregions = new HashSet<>();
- @Mock
- private RegionAttributes regionAttributes;
-
- @Mock
- private LocalRegion region;
- @Mock
- private GemFireCacheImpl cache;
- @Mock
- private InternalResourceManager internalResourceManager;
- @Mock
- private FunctionContext functionContext;
- @InjectMocks
- private GetRegionsFunction getRegionsFunction;
-
- @Before
- public void before() throws Exception {
- System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "statsDisabled",
"true");
- getRegionsFunction = new GetRegionsFunction();
- MockitoAnnotations.initMocks(this);
-
-
when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class));
-
when(this.cache.getDistributedSystem()).thenReturn(mock(InternalDistributedSystem.class));
-
when(this.cache.getResourceManager()).thenReturn(this.internalResourceManager);
- when(functionContext.getResultSender()).thenReturn(testResultSender);
- when(functionContext.getCache()).thenReturn(cache);
- }
-
- @Test
- public void testExecuteWithoutRegions() throws Exception {
- getRegionsFunction.execute(functionContext);
- }
-
- @Test
- public void testExecuteWithRegions() throws Exception {
- when(cache.rootRegions()).thenReturn(regions);
- when(region.getFullPath()).thenReturn("/MyRegion");
-
- when(region.getParentRegion()).thenReturn(null);
- when(region.subregions(true)).thenReturn(subregions);
- when(region.subregions(false)).thenReturn(subregions);
- when(region.getAttributes()).thenReturn(regionAttributes);
- when(regionAttributes.getDataPolicy()).thenReturn(mock(DataPolicy.class));
- when(regionAttributes.getScope()).thenReturn(mock(Scope.class));
- regions.add(region);
- getRegionsFunction.execute(functionContext);
- }
-
- private static class TestResultSender implements ResultSender {
-
- @Override
- public void lastResult(final Object lastResult) {}
-
- @Override
- public void sendResult(final Object oneResult) {}
-
- @Override
- public void sendException(final Throwable t) {
- throw new RuntimeException(t);
- }
- }
-
-}
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionTest.java
index 82d1ef8..dd49ab6 100644
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionTest.java
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionTest.java
@@ -12,73 +12,104 @@
* or implied. See the License for the specific language governing permissions
and limitations under
* the License.
*/
-
package org.apache.geode.management.internal.cli.functions;
-import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
-import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.HashSet;
+import java.util.Set;
-import org.awaitility.core.ConditionTimeoutException;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.mockito.Mock;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.CancelCriterion;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.cache.Scope;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.ResultSender;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.control.InternalResourceManager;
public class GetRegionsFunctionTest {
- private enum STATE {
- INITIAL, BLOCKING, FINISHED
- };
+ @Rule
+ public RestoreSystemProperties restoreSystemProperties = new
RestoreSystemProperties();
+
+ @Mock
+ private RegionAttributes regionAttributes;
+
+ @Mock
+ private LocalRegion region;
+
+ @Mock
+ private GemFireCacheImpl cache;
- private static GetRegionsFunctionTest.STATE lockingThreadState =
- GetRegionsFunctionTest.STATE.INITIAL;
- private static AtomicBoolean lockAquired = new AtomicBoolean(false);
- private static AtomicBoolean functionExecuted = new AtomicBoolean(false);
+ @Mock
+ private InternalResourceManager internalResourceManager;
- private GetRegionsFunction getRegionsFunction;
+ @Mock
private FunctionContext functionContext;
+ private final TestResultSender testResultSender = new TestResultSender();
+ private final Set<Region<?, ?>> regions = new HashSet<>();
+ private final Set<Region<?, ?>> subregions = new HashSet<>();
+ private final GetRegionsFunction getRegionsFunction = new
GetRegionsFunction();
+
@Before
public void before() {
- getRegionsFunction = new GetRegionsFunction();
- functionContext = mock(FunctionContext.class);
+ System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "statsDisabled",
"true");
+
+ initMocks(this);
+
+ when(cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class));
+
when(cache.getDistributedSystem()).thenReturn(mock(InternalDistributedSystem.class));
+ when(cache.getResourceManager()).thenReturn(internalResourceManager);
+ when(functionContext.getResultSender()).thenReturn(testResultSender);
+ when(functionContext.getCache()).thenReturn(cache);
+ }
+
+ @Test
+ public void testExecuteWithoutRegions() {
+ getRegionsFunction.execute(functionContext);
}
@Test
- public void doNotUseCacheFacotryToGetCache() throws Exception {
- // start a thread that would hold on to the CacheFactory's class lock
- new Thread(() -> {
- synchronized (CacheFactory.class) {
- lockAquired.set(true);
- lockingThreadState = GetRegionsFunctionTest.STATE.BLOCKING;
- try {
- await().untilTrue(functionExecuted);
- } catch (ConditionTimeoutException e) {
- e.printStackTrace();
- lockingThreadState = GetRegionsFunctionTest.STATE.FINISHED;
- }
- }
- }).start();
-
- // wait till the blocking thread aquired the lock on CacheFactory
- await().untilTrue(lockAquired);
- when(functionContext.getCache()).thenReturn(mock(Cache.class));
-
when(functionContext.getResultSender()).thenReturn(mock(ResultSender.class));
-
- // execute a function that would get the cache, make sure that's not
waiting on the lock
- // of CacheFactory
+ public void testExecuteWithRegions() {
+ when(cache.rootRegions()).thenReturn(regions);
+ when(region.getFullPath()).thenReturn("/MyRegion");
+
+ when(region.getParentRegion()).thenReturn(null);
+ when(region.subregions(true)).thenReturn(subregions);
+ when(region.subregions(false)).thenReturn(subregions);
+ when(region.getAttributes()).thenReturn(regionAttributes);
+ when(regionAttributes.getDataPolicy()).thenReturn(mock(DataPolicy.class));
+ when(regionAttributes.getScope()).thenReturn(mock(Scope.class));
+ regions.add(region);
getRegionsFunction.execute(functionContext);
- assertThat(lockingThreadState).isEqualTo(lockingThreadState.BLOCKING);
+ }
+
+ private static class TestResultSender implements ResultSender {
+ @Override
+ public void lastResult(final Object lastResult) {}
- // this will make the awaitility call in the thread return
- functionExecuted.set(true);
+ @Override
+ public void sendResult(final Object oneResult) {}
+
+ @Override
+ public void sendException(final Throwable t) {
+ throw new RuntimeException(t);
+ }
}
+
}