Repository: geode Updated Branches: refs/heads/develop 0ea489ea5 -> 56d964f86
GEODE-393: revert - GetRegionFunction uses the cache in the FunctionContext Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/56d964f8 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/56d964f8 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/56d964f8 Branch: refs/heads/develop Commit: 56d964f867cd27a1489ebe3343c93b84c55cd8a9 Parents: 0ea489e Author: Jinmei Liao <jil...@pivotal.io> Authored: Fri Jul 21 14:08:49 2017 -0700 Committer: Jinmei Liao <jil...@pivotal.io> Committed: Fri Jul 21 14:08:49 2017 -0700 ---------------------------------------------------------------------- .../cli/functions/GetRegionsFunction.java | 3 +- .../cli/functions/GetRegionsFunctionTest.java | 88 -------------------- 2 files changed, 2 insertions(+), 89 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/56d964f8/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunction.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunction.java index 6571dca..d524924 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunction.java @@ -18,6 +18,7 @@ import java.util.HashSet; import java.util.Set; import org.apache.geode.cache.Cache; +import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionContext; @@ -40,7 +41,7 @@ public class GetRegionsFunction implements Function, InternalEntity { @Override public void execute(FunctionContext functionContext) { try { - Cache cache = functionContext.getCache(); + Cache cache = CacheFactory.getAnyInstance(); Set<Region<?, ?>> regions = cache.rootRegions(); // should never return a null if (regions == null || regions.isEmpty()) { http://git-wip-us.apache.org/repos/asf/geode/blob/56d964f8/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionTest.java ---------------------------------------------------------------------- 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 deleted file mode 100644 index 77db7cd..0000000 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/functions/GetRegionsFunctionTest.java +++ /dev/null @@ -1,88 +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.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.awaitility.core.ConditionTimeoutException; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; -import org.apache.geode.cache.execute.FunctionContext; -import org.apache.geode.cache.execute.ResultSender; -import org.apache.geode.test.junit.categories.UnitTest; - -@Category(UnitTest.class) -public class GetRegionsFunctionTest { - - private enum STATE { - INITIAL, BLOCKING, FINISHED - }; - - private static GetRegionsFunctionTest.STATE lockingThreadState = - GetRegionsFunctionTest.STATE.INITIAL; - private static AtomicBoolean lockAquired = new AtomicBoolean(false); - private static AtomicBoolean functionExecuted = new AtomicBoolean(false); - - private GetRegionsFunction getRegionsFunction; - private FunctionContext functionContext; - - @Before - public void before() { - getRegionsFunction = new GetRegionsFunction(); - functionContext = mock(FunctionContext.class); - } - - @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().atMost(10, TimeUnit.SECONDS).untilTrue(functionExecuted); - } catch (ConditionTimeoutException e) { - e.printStackTrace(); - lockingThreadState = GetRegionsFunctionTest.STATE.FINISHED; - } - } - }).start(); - - // wait till the blocking thread aquired the lock on CacheFactory - await().atMost(1, TimeUnit.SECONDS).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 - getRegionsFunction.execute(functionContext); - assertThat(lockingThreadState).isEqualTo(lockingThreadState.BLOCKING); - - - // this will make the awaitility call in the thread return - functionExecuted.set(true); - } -}