This is an automated email from the ASF dual-hosted git repository. eshu11 pushed a commit to branch feature/GEODE-7537 in repository https://gitbox.apache.org/repos/asf/geode.git
commit 8b98b009e3b148983b9cdaf7c3e340c5ba1ac629 Author: Eric Shu <[email protected]> AuthorDate: Mon Dec 16 13:32:34 2019 -0800 Revert "GEODE-7537: Remove the synchronization in CacheFactoryStatics.getAnyInstance. (#4435)" This reverts commit 3a3db82afdf0668e98ca49bcbdfa478e0ac94e10. --- .../cache/CacheFactoryStaticsIntegrationTest.java | 71 ---------------------- .../geode/internal/cache/CacheFactoryStatics.java | 16 ++--- 2 files changed, 9 insertions(+), 78 deletions(-) diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/CacheFactoryStaticsIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/CacheFactoryStaticsIntegrationTest.java deleted file mode 100644 index 98c5467..0000000 --- a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/CacheFactoryStaticsIntegrationTest.java +++ /dev/null @@ -1,71 +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.internal.cache; - -import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static org.apache.geode.test.awaitility.GeodeAwaitility.await; -import static org.apache.geode.test.awaitility.GeodeAwaitility.getTimeout; - -import java.util.Properties; -import java.util.concurrent.CountDownLatch; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ErrorCollector; - -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; -import org.apache.geode.test.junit.rules.ExecutorServiceRule; - -public class CacheFactoryStaticsIntegrationTest { - - private final CountDownLatch latch = new CountDownLatch(1); - - private Cache cache; - - @Rule - public ErrorCollector errorCollector = new ErrorCollector(); - - @Rule - public ExecutorServiceRule executorServiceRule = new ExecutorServiceRule(); - - @Before - public void setUp() { - cache = new CacheFactory(new Properties()).create(); - } - - @After - public void after() { - cache.close(); - } - - @Test - public void cacheFactoryStaticsGetAnyInstanceDoesNotRequireSynchronizedLock() throws Exception { - synchronized (InternalCacheBuilder.class) { - executorServiceRule.submit(() -> { - try { - await().until(() -> CacheFactoryStatics.getAnyInstance() != null); - } catch (Exception e) { - errorCollector.addError(e); - } finally { - latch.countDown(); - } - }); - latch.await(getTimeout().getValueInMS(), MILLISECONDS); - } - } -} diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/CacheFactoryStatics.java b/geode-core/src/main/java/org/apache/geode/internal/cache/CacheFactoryStatics.java index ce4998e..9b0f989 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/CacheFactoryStatics.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/CacheFactoryStatics.java @@ -81,13 +81,15 @@ public class CacheFactoryStatics { * {@link Cache#isClosed closed} */ public static Cache getAnyInstance() { - InternalCache instance = GemFireCacheImpl.getInstance(); - if (instance == null) { - throw new CacheClosedException( - "A cache has not yet been created."); - } else { - instance.getCancelCriterion().checkCancelInProgress(null); - return instance; + synchronized (InternalCacheBuilder.class) { + InternalCache instance = GemFireCacheImpl.getInstance(); + if (instance == null) { + throw new CacheClosedException( + "A cache has not yet been created."); + } else { + instance.getCancelCriterion().checkCancelInProgress(null); + return instance; + } } }
