You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2018/03/29 20:22:00 UTC
[geode] 04/15: GEODE-4876: Update RegionClearStatsDistributedTest
use of VM and NetworkUtils
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
commit e55082a280ad65d47933400dcc4a575834fe7cae
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Mon Mar 26 17:27:37 2018 -0700
GEODE-4876: Update RegionClearStatsDistributedTest use of VM and NetworkUtils
* rename CacheRegionClearStatsDUnitTest as RegionClearStatsDistributedTest
* cleanup test
---
.../cache/CacheRegionClearStatsDUnitTest.java | 241 ---------------------
.../cache/RegionClearStatsDistributedTest.java | 179 +++++++++++++++
2 files changed, 179 insertions(+), 241 deletions(-)
diff --git a/geode-core/src/test/java/org/apache/geode/cache/CacheRegionClearStatsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/CacheRegionClearStatsDUnitTest.java
deleted file mode 100755
index 41704d8..0000000
--- a/geode-core/src/test/java/org/apache/geode/cache/CacheRegionClearStatsDUnitTest.java
+++ /dev/null
@@ -1,241 +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.cache;
-
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.util.Properties;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.client.PoolManager;
-import org.apache.geode.cache.client.internal.PoolImpl;
-import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.NetworkUtils;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * verifies the count of clear operation
- */
-@Category(DistributedTest.class)
-public class CacheRegionClearStatsDUnitTest extends JUnit4DistributedTestCase {
-
- /** the cache */
- private static GemFireCacheImpl cache = null;
-
- private VM server1 = null;
-
- private static VM client1 = null;
-
- /** name of the test region */
- private static final String REGION_NAME = "CacheRegionClearStatsDUnitTest_Region";
-
- private static final String k1 = "k1";
-
- private static final String k2 = "k2";
-
- private static final String client_k1 = "client-k1";
-
- private static final String client_k2 = "client-k2";
-
- private static final int clearOp = 2;
-
- @Override
- public final void postSetUp() throws Exception {
- final Host host = Host.getHost(0);
- server1 = host.getVM(0);
- client1 = host.getVM(1);
- }
-
- private void createCache(Properties props) throws Exception {
- DistributedSystem ds = getSystem(props);
- ds.disconnect();
- ds = getSystem(props);
- assertNotNull(ds);
- cache = (GemFireCacheImpl) CacheFactory.create(ds);
- assertNotNull(cache);
- }
-
- public static void createClientCache(String host, Integer port1) throws Exception {
- new CacheRegionClearStatsDUnitTest();
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, "");
- new CacheRegionClearStatsDUnitTest().createCache(props);
- PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host, port1.intValue())
- .setSubscriptionEnabled(false).setThreadLocalConnections(true).setMinConnections(1)
- .setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(1)
- .create("CacheRegionClearStatsDUnitTest");
-
- AttributesFactory factory = new AttributesFactory();
- factory.setScope(Scope.DISTRIBUTED_ACK);
- factory.setPoolName(p.getName());
-
- RegionAttributes attrs = factory.create();
- Region region = cache.createRegion(REGION_NAME, attrs);
- // region.registerInterest("ALL_KEYS");
- }
-
- public static Integer createServerCacheDisk() throws Exception {
- return createCache(DataPolicy.PERSISTENT_REPLICATE);
- }
-
- private static Integer createCache(DataPolicy dataPolicy) throws Exception {
- new CacheRegionClearStatsDUnitTest().createCache(new Properties());
- AttributesFactory factory = new AttributesFactory();
- factory.setScope(Scope.DISTRIBUTED_ACK);
- factory.setDataPolicy(dataPolicy);
- RegionAttributes attrs = factory.create();
- cache.createRegion(REGION_NAME, attrs);
- int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
- CacheServer server1 = cache.addCacheServer();
- server1.setPort(port);
- server1.setNotifyBySubscription(true);
- server1.start();
- return new Integer(server1.getPort());
- }
-
- public static Integer createServerCache() throws Exception {
- return createCache(DataPolicy.REPLICATE);
- }
-
- public static void createClientCacheDisk(String host, Integer port1) throws Exception {
- new CacheRegionClearStatsDUnitTest();
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, "");
- new CacheRegionClearStatsDUnitTest().createCache(props);
- PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host, port1.intValue())
- .setSubscriptionEnabled(false).setThreadLocalConnections(true).setMinConnections(1)
- .setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(1)
- .create("CacheRegionClearStatsDUnitTest");
-
- AttributesFactory factory = new AttributesFactory();
- factory.setScope(Scope.DISTRIBUTED_ACK);
- factory.setPoolName(p.getName());
- factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
- RegionAttributes attrs = factory.create();
- Region region = cache.createRegion(REGION_NAME, attrs);
- // region.registerInterest("ALL_KEYS");
- }
-
- /**
- * This test does the following (<b> clear stats counter </b>):<br>
- * 1)Verifies that clear operation count matches with stats count<br>
- */
- @Test
- public void testClearStatsWithNormalRegion() {
- Integer port1 =
- ((Integer) server1.invoke(() -> CacheRegionClearStatsDUnitTest.createServerCache()));
-
- client1.invoke(() -> CacheRegionClearStatsDUnitTest
- .createClientCache(NetworkUtils.getServerHostName(server1.getHost()), port1));
- client1.invoke(() -> CacheRegionClearStatsDUnitTest.put());
-
- try {
- Thread.sleep(10000);
- } catch (Exception e) {
- // sleep
- }
-
- client1.invoke(() -> CacheRegionClearStatsDUnitTest.validationClearStat());
-
- server1.invoke(() -> CacheRegionClearStatsDUnitTest.validationClearStat());
- }
-
- /**
- * This test does the following (<b> clear stats counter when disk involved </b>):<br>
- * 1)Verifies that clear operation count matches with stats count <br>
- */
- @Test
- public void testClearStatsWithDiskRegion() {
- Integer port1 =
- ((Integer) server1.invoke(() -> CacheRegionClearStatsDUnitTest.createServerCacheDisk()));
-
- client1.invoke(() -> CacheRegionClearStatsDUnitTest
- .createClientCacheDisk(NetworkUtils.getServerHostName(server1.getHost()), port1));
- client1.invoke(() -> CacheRegionClearStatsDUnitTest.put());
-
- try {
- Thread.sleep(10000);
- } catch (Exception e) {
- // sleep
- }
-
- client1.invoke(() -> CacheRegionClearStatsDUnitTest.validationClearStat());
-
- server1.invoke(() -> CacheRegionClearStatsDUnitTest.validationClearStat());
- }
-
- @Override
- public final void preTearDown() throws Exception {
- client1.invoke(() -> CacheRegionClearStatsDUnitTest.closeCache());
- // then close the servers
- server1.invoke(() -> CacheRegionClearStatsDUnitTest.closeCache());
- }
-
- public static void closeCache() {
- if (cache != null && !cache.isClosed()) {
- cache.close();
- cache.getDistributedSystem().disconnect();
- }
- }
-
- public static void put() {
- try {
- Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
- assertNotNull(r1);
-
- r1.put(k1, client_k1);
- assertEquals(r1.getEntry(k1).getValue(), client_k1);
- r1.put(k2, client_k2);
- assertEquals(r1.getEntry(k2).getValue(), client_k2);
- try {
- Thread.sleep(10000);
- } catch (Exception e) {
- // sleep
- }
- r1.clear();
-
- r1.put(k1, client_k1);
- assertEquals(r1.getEntry(k1).getValue(), client_k1);
- r1.put(k2, client_k2);
- assertEquals(r1.getEntry(k2).getValue(), client_k2);
- try {
- Thread.sleep(10000);
- } catch (Exception e) {
- // sleep
- }
- r1.clear();
- } catch (Exception ex) {
- Assert.fail("failed while put", ex);
- }
- }
-
- public static void validationClearStat() {
- assertEquals(cache.getCachePerfStats().getClearCount(), clearOp);
- }
-
-
-}
diff --git a/geode-core/src/test/java/org/apache/geode/cache/RegionClearStatsDistributedTest.java b/geode-core/src/test/java/org/apache/geode/cache/RegionClearStatsDistributedTest.java
new file mode 100755
index 0000000..1b955e2
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/cache/RegionClearStatsDistributedTest.java
@@ -0,0 +1,179 @@
+/*
+ * 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.cache;
+
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.test.dunit.NetworkUtils.getServerHostName;
+import static org.apache.geode.test.dunit.VM.getVM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.rules.CacheRule;
+import org.apache.geode.test.dunit.rules.DistributedTestRule;
+import org.apache.geode.test.junit.categories.DistributedTest;
+
+/**
+ * verifies the count of clear operation
+ */
+@Category(DistributedTest.class)
+@SuppressWarnings("serial")
+public class RegionClearStatsDistributedTest implements Serializable {
+
+ private static final String REGION_NAME = RegionClearStatsDistributedTest.class.getSimpleName();
+ private static final String KEY1 = "k1";
+ private static final String KEY2 = "k2";
+ private static final String VALUE1 = "client-k1";
+ private static final String VALUE2 = "client-k2";
+ private static final int EXPECTED_CLEAR_COUNT_STAT_VALUE = 2;
+
+ private VM server1;
+ private VM client1;
+
+ @ClassRule
+ public static DistributedTestRule distributedTestRule = new DistributedTestRule();
+
+ @Rule
+ public CacheRule cacheRule = new CacheRule();
+
+ @Before
+ public void setUp() throws Exception {
+ server1 = getVM(0);
+ client1 = getVM(1);
+ }
+
+ /**
+ * Verifies that clear operation count matches with stats count
+ */
+ @Test
+ public void testClearStatsWithNormalRegion() {
+ int port = server1.invoke(() -> createServerCache());
+ client1.invoke(() -> createClientCache(getServerHostName(), port));
+
+ client1.invoke(() -> doPutsAndClear());
+ client1.invoke(() -> doPutsAndClear());
+
+ client1.invoke(() -> validateClearCountStat());
+ server1.invoke(() -> validateClearCountStat());
+ }
+
+ /**
+ * Verifies that clear operation count matches with stats count with persistence
+ */
+ @Test
+ public void testClearStatsWithDiskRegion() {
+ int port = server1.invoke(() -> createServerCacheWithPersistence());
+ client1.invoke(() -> createClientCacheWithPersistence(getServerHostName(), port));
+
+ client1.invoke(() -> doPutsAndClear());
+ client1.invoke(() -> doPutsAndClear());
+
+ client1.invoke(() -> validateClearCountStat());
+ server1.invoke(() -> validateClearCountStat());
+ }
+
+ private int createCache(DataPolicy dataPolicy) throws IOException {
+ cacheRule.createCache();
+
+ AttributesFactory factory = new AttributesFactory();
+ factory.setScope(Scope.DISTRIBUTED_ACK);
+ factory.setDataPolicy(dataPolicy);
+
+ cacheRule.getCache().createRegion(REGION_NAME, factory.create());
+
+ CacheServer server1 = cacheRule.getCache().addCacheServer();
+ server1.setPort(0);
+ server1.setNotifyBySubscription(true);
+ server1.start();
+ return server1.getPort();
+ }
+
+ private int createServerCacheWithPersistence() throws IOException {
+ return createCache(DataPolicy.PERSISTENT_REPLICATE);
+ }
+
+ private int createServerCache() throws IOException {
+ return createCache(DataPolicy.REPLICATE);
+ }
+
+ private void createClientCache(String host, int port) {
+ Properties config = new Properties();
+ config.setProperty(MCAST_PORT, "0");
+ config.setProperty(LOCATORS, "");
+
+ cacheRule.createCache(config);
+
+ PoolImpl pool =
+ (PoolImpl) PoolManager.createFactory().addServer(host, port).setSubscriptionEnabled(false)
+ .setThreadLocalConnections(true).setMinConnections(1).setReadTimeout(20000)
+ .setPingInterval(10000).setRetryAttempts(1).create(getClass().getSimpleName());
+
+ AttributesFactory factory = new AttributesFactory();
+ factory.setScope(Scope.DISTRIBUTED_ACK);
+ factory.setPoolName(pool.getName());
+
+ cacheRule.getCache().createRegion(REGION_NAME, factory.create());
+ }
+
+ private void createClientCacheWithPersistence(String host, int port) {
+ Properties props = new Properties();
+ props.setProperty(MCAST_PORT, "0");
+ props.setProperty(LOCATORS, "");
+
+ cacheRule.createCache(props);
+
+ PoolImpl pool =
+ (PoolImpl) PoolManager.createFactory().addServer(host, port).setSubscriptionEnabled(false)
+ .setThreadLocalConnections(true).setMinConnections(1).setReadTimeout(20000)
+ .setPingInterval(10000).setRetryAttempts(1).create(getClass().getSimpleName());
+
+ AttributesFactory factory = new AttributesFactory();
+ factory.setScope(Scope.DISTRIBUTED_ACK);
+ factory.setPoolName(pool.getName());
+ factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+
+ cacheRule.getCache().createRegion(REGION_NAME, factory.create());
+ }
+
+ private void doPutsAndClear() {
+ Region region = cacheRule.getCache().getRegion(REGION_NAME);
+
+ region.put(KEY1, VALUE1);
+ region.put(KEY2, VALUE2);
+
+ assertThat(region.getEntry(KEY1).getValue()).isEqualTo(VALUE1);
+ assertThat(region.getEntry(KEY2).getValue()).isEqualTo(VALUE2);
+
+ region.clear();
+ }
+
+ private void validateClearCountStat() {
+ assertThat(cacheRule.getCache().getCachePerfStats().getClearCount())
+ .isEqualTo(EXPECTED_CLEAR_COUNT_STAT_VALUE);
+ }
+}
--
To stop receiving notification emails like this one, please contact
klund@apache.org.