You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by pr...@apache.org on 2018/04/04 21:39:45 UTC
[geode] branch develop updated: GEODE-4456: Remove singleton calls
from all tests in org.apache.geode.internal.cache
This is an automated email from the ASF dual-hosted git repository.
prhomberg 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 da1ce1c GEODE-4456: Remove singleton calls from all tests in org.apache.geode.internal.cache
da1ce1c is described below
commit da1ce1c0da9f8d9feea27f54ba2b84c344102c55
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Wed Apr 4 14:39:40 2018 -0700
GEODE-4456: Remove singleton calls from all tests in org.apache.geode.internal.cache
* removed InternalDistributedSystem.getConnectedInstance call from TombstoneCreationJUnitTest
* Also the cache is now created in a @Before method and uses non-deprecated methods to create it.
* removed InternalDistributedSystem.getConnectedInstance call from ClientServerTransactionDUnitTest
* removed getAnyInstance calls in GridAdvisorDUnitTest
---
.../cache/ClientServerTransactionDUnitTest.java | 11 +--
.../geode/internal/cache/GridAdvisorDUnitTest.java | 86 +++++++++++-----------
.../internal/cache/TombstoneCreationJUnitTest.java | 45 +++++------
3 files changed, 62 insertions(+), 80 deletions(-)
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ClientServerTransactionDUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ClientServerTransactionDUnitTest.java
index 19cc81e..5b764f0 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/ClientServerTransactionDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/ClientServerTransactionDUnitTest.java
@@ -372,16 +372,9 @@ public class ClientServerTransactionDUnitTest extends RemoteTransactionDUnitTest
exceptionThrown = true;
}
- SerializableCallable disconnect = new SerializableCallable("disconnect") {
- public Object call() throws Exception {
- InternalDistributedSystem.getConnectedInstance().disconnect();
- return null;
- }
- };
-
cCache.close();
- datastore1.invoke(disconnect);
- datastore2.invoke(disconnect);
+ datastore1.invoke(() -> closeCache());
+ datastore2.invoke(() -> closeCache());
if (!exceptionThrown) {
fail("expected TransactionException to be thrown since two pools were used");
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/GridAdvisorDUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/GridAdvisorDUnitTest.java
index 2edbf2a..5527162 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/GridAdvisorDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/GridAdvisorDUnitTest.java
@@ -29,10 +29,8 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.distributed.Locator;
import org.apache.geode.distributed.internal.DistributionAdvisee;
-import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.internal.AvailablePort.Keeper;
import org.apache.geode.internal.AvailablePortHelper;
@@ -53,6 +51,19 @@ import org.apache.geode.test.junit.categories.DistributedTest;
@Category(DistributedTest.class)
public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
+ private static InternalCache cache;
+
+ private void createCache(String locators, String groups) {
+ Properties props = new Properties();
+ props.setProperty(MCAST_PORT, "0");
+ props.setProperty(LOCATORS, locators);
+ if (groups != null) {
+ props.setProperty(GROUPS, groups);
+ }
+ props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
+ cache = (InternalCache) new CacheFactory(props).create();
+ }
+
/**
* Tests 2 controllers and 2 bridge servers
*/
@@ -118,11 +129,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable connect = new SerializableRunnable("Connect to " + locators) {
public void run() {
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
- dsProps.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- CacheFactory.create(DistributedSystem.connect(props));
+ createCache(locators, null);
}
};
vm1.invoke(connect);
@@ -130,7 +137,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable startBS1 = new SerializableRunnable("start bridgeServer on " + bsPort1) {
public void run() {
try {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort1);
bs.setGroups(new String[] {"bs1Group1", "bs1Group2"});
@@ -145,7 +152,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable startBS3 = new SerializableRunnable("start bridgeServer on " + bsPort3) {
public void run() {
try {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort3);
bs.setGroups(new String[] {"bs3Group1", "bs3Group2"});
@@ -166,7 +173,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort2) {
public void run() {
try {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort2);
bs.setGroups(new String[] {"bs2Group1", "bs2Group2"});
@@ -182,7 +189,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort4) {
public void run() {
try {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort4);
bs.setGroups(new String[] {"bs4Group1", "bs4Group2"});
@@ -273,7 +280,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
vm1.invoke(
new SerializableRunnable("Verify bridge server view on " + bsPort1 + " and on " + bsPort3) {
public void run() {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
@@ -303,7 +310,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
vm2.invoke(
new SerializableRunnable("Verify bridge server view on " + bsPort2 + " and on " + bsPort4) {
public void run() {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
@@ -333,7 +340,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable stopBS = new SerializableRunnable("stop bridge server") {
public void run() {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
CacheServer bs = (CacheServer) bslist.get(0);
@@ -414,10 +421,9 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {
public void run() {
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
- DistributedSystem.connect(props).disconnect();
+ if (cache != null) {
+ cache.close();
+ }
}
};
SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {
@@ -443,7 +449,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
});
vm2.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {
public void run() {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
@@ -466,7 +472,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
});
vm1.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {
public void run() {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
@@ -495,7 +501,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable restartBS = new SerializableRunnable("restart bridge server") {
public void run() {
try {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
CacheServer bs = (CacheServer) bslist.get(0);
@@ -623,29 +629,19 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
vm1.invoke(new SerializableRunnable("Connect to " + locators) {
public void run() {
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
- props.setProperty(GROUPS, "bs1Group1, bs1Group2");
- props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- CacheFactory.create(DistributedSystem.connect(props));
+ createCache(locators, "bs1Group1, bs1Group2");
}
});
vm2.invoke(new SerializableRunnable("Connect to " + locators) {
public void run() {
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
- props.setProperty(GROUPS, "bs2Group1, bs2Group2");
- props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
- CacheFactory.create(DistributedSystem.connect(props));
+ createCache(locators, "bs2Group1, bs2Group2");
}
});
SerializableRunnable startBS1 = new SerializableRunnable("start bridgeServer on " + bsPort1) {
public void run() {
try {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort1);
bs.start();
@@ -659,7 +655,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable startBS3 = new SerializableRunnable("start bridgeServer on " + bsPort3) {
public void run() {
try {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort3);
bs.start();
@@ -679,7 +675,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort2) {
public void run() {
try {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort2);
bs.start();
@@ -694,7 +690,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
vm2.invoke(new SerializableRunnable("start bridgeServer on " + bsPort4) {
public void run() {
try {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
CacheServer bs = c.addCacheServer();
bs.setPort(bsPort4);
bs.start();
@@ -784,7 +780,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
vm1.invoke(
new SerializableRunnable("Verify bridge server view on " + bsPort1 + " and on " + bsPort3) {
public void run() {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
@@ -814,7 +810,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
vm2.invoke(
new SerializableRunnable("Verify bridge server view on " + bsPort2 + " and on " + bsPort4) {
public void run() {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
@@ -844,7 +840,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable stopBS = new SerializableRunnable("stop bridge server") {
public void run() {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
CacheServer bs = (CacheServer) bslist.get(0);
@@ -925,7 +921,9 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable disconnect = new SerializableRunnable("Disconnect from " + locators) {
public void run() {
- InternalDistributedSystem.getAnyInstance().disconnect();
+ if (cache != null) {
+ cache.close();
+ }
}
};
SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {
@@ -951,7 +949,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
});
vm2.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {
public void run() {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
@@ -974,7 +972,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
});
vm1.invoke(new SerializableRunnable("Verify bridge server saw locator stop") {
public void run() {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
for (int i = 0; i < bslist.size(); i++) {
@@ -1003,7 +1001,7 @@ public class GridAdvisorDUnitTest extends JUnit4DistributedTestCase {
SerializableRunnable restartBS = new SerializableRunnable("restart bridge server") {
public void run() {
try {
- Cache c = CacheFactory.getAnyInstance();
+ Cache c = cache;
List bslist = c.getCacheServers();
assertEquals(2, bslist.size());
CacheServer bs = (CacheServer) bslist.get(0);
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/TombstoneCreationJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/TombstoneCreationJUnitTest.java
index 5dd2f8b..6de8cbe 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/TombstoneCreationJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/TombstoneCreationJUnitTest.java
@@ -14,20 +14,24 @@
*/
package org.apache.geode.internal.cache;
-import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import java.net.InetAddress;
-import java.util.Properties;
import org.junit.After;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
-import org.apache.geode.cache.*;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.EntryNotFoundException;
+import org.apache.geode.cache.Operation;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.internal.Assert;
import org.apache.geode.internal.cache.entries.VersionedThinRegionEntryHeap;
@@ -40,23 +44,22 @@ public class TombstoneCreationJUnitTest {
@Rule
public TestName nameRule = new TestName();
+ private GemFireCacheImpl cache;
+
+ @Before
+ public void setUp() {
+ this.cache = (GemFireCacheImpl) new CacheFactory().set(LOCATORS, "").set(MCAST_PORT, "0")
+ .set(LOG_LEVEL, "config").create();
+ }
+
@After
public void tearDown() {
- InternalDistributedSystem system = InternalDistributedSystem.getConnectedInstance();
- if (system != null) {
- system.disconnect();
- }
+ this.cache.close();
}
@Test
public void testDestroyCreatesTombstone() throws Exception {
String name = nameRule.getMethodName();
- Properties props = new Properties();
- props.put(LOCATORS, "");
- props.put(MCAST_PORT, "0");
- props.put(LOG_LEVEL, "config");
- GemFireCacheImpl cache =
- (GemFireCacheImpl) CacheFactory.create(DistributedSystem.connect(props));
RegionFactory f = cache.createRegionFactory(RegionShortcut.REPLICATE);
DistributedRegion region = (DistributedRegion) f.create(name);
@@ -89,12 +92,6 @@ public class TombstoneCreationJUnitTest {
@Test
public void testConcurrentCreateAndDestroy() throws Exception {
String name = nameRule.getMethodName();
- Properties props = new Properties();
- props.put(LOCATORS, "");
- props.put(MCAST_PORT, "0");
- props.put(LOG_LEVEL, "config");
- final GemFireCacheImpl cache =
- (GemFireCacheImpl) CacheFactory.create(DistributedSystem.connect(props));
RegionFactory f = cache.createRegionFactory(RegionShortcut.REPLICATE);
final DistributedRegion region = (DistributedRegion) f.create(name);
@@ -165,12 +162,6 @@ public class TombstoneCreationJUnitTest {
@Test
public void testOlderEventIgnoredEvenIfTombstoneHasExpired() throws Exception {
String name = nameRule.getMethodName();
- Properties props = new Properties();
- props.put(LOCATORS, "");
- props.put(MCAST_PORT, "0");
- props.put(LOG_LEVEL, "config");
- final GemFireCacheImpl cache =
- (GemFireCacheImpl) CacheFactory.create(DistributedSystem.connect(props));
RegionFactory f = cache.createRegionFactory(RegionShortcut.REPLICATE);
final DistributedRegion region = (DistributedRegion) f.create(name);
--
To stop receiving notification emails like this one, please contact
prhomberg@apache.org.