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/04/23 05:46:49 UTC
[geode] 11/13: GEODE-1279: Rename
DeltaPropagationFailureRegressionTest
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 2e22ab16b409aa70dcca4f09faf908fe33858c2b
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri Apr 20 16:13:07 2018 -0700
GEODE-1279: Rename DeltaPropagationFailureRegressionTest
* Bug40396DUnitTest -> DeltaPropagationFailureRegressionTest
---
.../internal/cache/tier/Bug40396DUnitTest.java | 217 ---------------------
.../DeltaPropagationFailureRegressionTest.java | 155 +++++++++++++++
2 files changed, 155 insertions(+), 217 deletions(-)
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/Bug40396DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/Bug40396DUnitTest.java
deleted file mode 100755
index aa01b89..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/Bug40396DUnitTest.java
+++ /dev/null
@@ -1,217 +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.tier;
-
-import static org.junit.Assert.*;
-
-import java.util.Properties;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.AttributesFactory;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-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.server.CacheServer;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.internal.cache.tier.sockets.DeltaEOFException;
-import org.apache.geode.internal.cache.tier.sockets.FaultyDelta;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.Invoke;
-import org.apache.geode.test.dunit.SerializableRunnable;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.junit.categories.ClientServerTest;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Test delta propagation for faulty delta implementation
- *
- * @since GemFire 6.1
- */
-@Category({DistributedTest.class, ClientServerTest.class})
-public class Bug40396DUnitTest extends JUnit4DistributedTestCase {
-
- private static Cache cache;
- private static final String REGION_NAME = "Bug40396DUnitTest_region";
-
- private static final String END_OF_FILE_EX = "eofe";
- private static final String ARRAY_INDEX_OUT_BOUND_EX = "aiob";
-
- private static int counter;
-
- private VM server;
- private VM server2;
-
- private static final int PUT_COUNT = 10;
-
- public Bug40396DUnitTest() {
- super();
- }
-
- @Override
- public final void postSetUp() throws Exception {
- disconnectAllFromDS();
- final Host host = Host.getHost(0);
- server = host.getVM(0);
- server2 = host.getVM(2);
- }
-
- /*
- * create server cache
- */
- public static Integer createServerCache() throws Exception {
- new Bug40396DUnitTest().createCache(new Properties());
- AttributesFactory factory = new AttributesFactory();
- factory.setScope(Scope.DISTRIBUTED_ACK);
- factory.setDataPolicy(DataPolicy.REPLICATE);
- RegionAttributes attrs = factory.create();
- Region region = cache.createRegion(REGION_NAME, attrs);
- region.getAttributesMutator().setCloningEnabled(false);
- CacheServer server = cache.addCacheServer();
- addExceptions();
- int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
- server.setPort(port);
- // ensures updates to be sent instead of invalidations
- server.setNotifyBySubscription(true);
- server.start();
- return new Integer(server.getPort());
-
- }
-
- public static void addExceptions() throws Exception {
- if (cache != null && !cache.isClosed()) {
- cache.getLogger()
- .info("<ExpectedException action=add>" + "java.io.EOFException" + "</ExpectedException>");
- cache.getLogger().info("<ExpectedException action=add>"
- + "java.lang.ArrayIndexOutOfBoundsException" + "</ExpectedException>");
- }
- }
-
- public static void removeExceptions() {
- if (cache != null && !cache.isClosed()) {
- cache.getLogger().info(
- "<ExpectedException action=remove>" + "java.io.EOFException" + "</ExpectedException>");
- cache.getLogger().info("<ExpectedException action=remove>"
- + "java.lang.ArrayIndexOutOfBoundsException" + "</ExpectedException>");
- }
- }
-
- /*
- * create cache with properties
- */
- private void createCache(Properties props) throws Exception {
- DistributedSystem ds = getSystem(props);
- cache = CacheFactory.create(ds);
- assertNotNull(cache);
- }
-
- public static void closeCache() {
- if (cache != null && !cache.isClosed()) {
- cache.close();
- cache.getDistributedSystem().disconnect();
- }
- }
-
- public static Exception putDelta(String regName, String type) {
- Region reg = cache.getRegion(Region.SEPARATOR + regName);
- try {
- if (type.equals(END_OF_FILE_EX)) {
- DeltaEOFException obj = new DeltaEOFException();
- for (int i = 0; i < PUT_COUNT; i++) {
- obj.setIntVal(i);
- obj.setBigObj(new byte[] {(byte) (i + 3), (byte) (i + 3)});
- reg.put("key", obj);
- }
- } else if (type.equals(ARRAY_INDEX_OUT_BOUND_EX)) {
- FaultyDelta obj = new FaultyDelta();
- for (int i = 0; i < PUT_COUNT; i++) {
- obj.setIntVal(i);
- obj.setBigObj(new byte[] {(byte) (i + 3), (byte) (i + 3)});
- reg.put("key", obj);
- }
- }
- } catch (Exception ex) {
- return ex;
- }
- // this make tests fail
- return new Exception();
- }
-
- /**
- * This test does the following 1)send faulty implementation (Reading more in fromDelta then what
- * sent by toDelta) of delta raises EOF exception<br>
- */
- @Test
- public void testForFaultyDeltaImplementationForEOFEX() {
- boolean matched = false;
- ((Integer) server.invoke(() -> Bug40396DUnitTest.createServerCache())).intValue();
- ((Integer) server2.invoke(() -> Bug40396DUnitTest.createServerCache())).intValue();
- Exception xp =
- (Exception) server.invoke(() -> Bug40396DUnitTest.putDelta(REGION_NAME, END_OF_FILE_EX));
- StackTraceElement[] st = xp.getCause().getStackTrace();
- matched = getMatched(st);
-
- assertTrue("pattern not found", matched);
- }
-
- private boolean getMatched(StackTraceElement[] ste) {
- boolean mched = false;
- for (int i = 0; i < ste.length; i++) {
- if (mched)
- break;
- if (ste[i].toString().indexOf("fromDelta") != -1)
- mched = true;
- }
- return mched;
- }
-
- /**
- * This test does the following 1)send faulty implementation when reading incorrect order from
- * toDelta, raises delta raises array index out of bound exception<br>
- */
- @Test
- public void testForFaultyDeltaImplementationForAIOBEX() {
- boolean matched = false;
- ((Integer) server.invoke(() -> Bug40396DUnitTest.createServerCache())).intValue();
- ((Integer) server2.invoke(() -> Bug40396DUnitTest.createServerCache())).intValue();
- Exception xp = (Exception) server
- .invoke(() -> Bug40396DUnitTest.putDelta(REGION_NAME, ARRAY_INDEX_OUT_BOUND_EX));
-
- StackTraceElement[] st = xp.getStackTrace();
- matched = getMatched(st);
-
- assertTrue("pattern not found", matched);
- }
-
- @Override
- public final void preTearDown() throws Exception {
- // then close the servers
- server.invoke(() -> Bug40396DUnitTest.removeExceptions());
- server.invoke(() -> Bug40396DUnitTest.closeCache());
- server2.invoke(() -> Bug40396DUnitTest.closeCache());
- cache = null;
- Invoke.invokeInEveryVM(new SerializableRunnable() {
- public void run() {
- cache = null;
- }
- });
- }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/DeltaPropagationFailureRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/DeltaPropagationFailureRegressionTest.java
new file mode 100755
index 0000000..50e2cab
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/DeltaPropagationFailureRegressionTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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.tier;
+
+import static org.apache.geode.internal.cache.tier.DeltaPropagationFailureRegressionTest.DeltaFailure.FROM_DELTA;
+import static org.apache.geode.internal.cache.tier.DeltaPropagationFailureRegressionTest.DeltaFailure.TO_DELTA;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.apache.geode.test.dunit.VM.getVM;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.catchThrowable;
+
+import java.io.EOFException;
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.DeltaSerializationException;
+import org.apache.geode.cache.AttributesFactory;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.internal.cache.tier.sockets.DeltaEOFException;
+import org.apache.geode.internal.cache.tier.sockets.FaultyDelta;
+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.ClientServerTest;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+
+/**
+ * Test delta propagation for faulty delta implementation
+ *
+ * <p>
+ * TRAC #40396: Need better error messages (and unit tests) when users code delta propagation
+ * methods incorrectly
+ *
+ * @since GemFire 6.1
+ */
+@Category({DistributedTest.class, ClientServerTest.class})
+@SuppressWarnings("serial")
+public class DeltaPropagationFailureRegressionTest implements Serializable {
+
+ private static final int PUT_COUNT = 10;
+
+ private String regionName;
+
+ private VM server1;
+ private VM server2;
+
+ @Rule
+ public DistributedTestRule distributedTestRule = new DistributedTestRule();
+
+ @Rule
+ public CacheRule cacheRule = new CacheRule();
+
+ @Rule
+ public SerializableTestName testName = new SerializableTestName();
+
+ @Before
+ public void setUp() throws Exception {
+ server1 = getVM(0);
+ server2 = getVM(2);
+
+ regionName = getClass().getSimpleName() + "_" + testName.getMethodName();
+
+ server1.invoke(() -> createServerCache());
+ server2.invoke(() -> createServerCache());
+ }
+
+ /**
+ * Verifies error handling when trying to read more in fromDelta then what sent by toDelta which
+ * throws EOFException
+ */
+ @Test
+ public void fromDeltaThrowsDeltaSerializationExceptionWithCauseEofException() {
+ addIgnoredException(EOFException.class);
+
+ Throwable thrown = server1.invoke(() -> catchThrowable(() -> putDelta(FROM_DELTA)));
+
+ assertThat(thrown).isInstanceOf(DeltaSerializationException.class)
+ .hasMessageContaining("deserializing delta bytes").hasCauseInstanceOf(EOFException.class);
+ }
+
+ /**
+ * Verifies error handling when reading incorrect order from toDelta which throws
+ * ArrayIndexOutOfBoundsException
+ */
+ @Test
+ public void toDeltaThrowsArrayIndexOutOfBoundsException() {
+ addIgnoredException(ArrayIndexOutOfBoundsException.class);
+
+ Throwable thrown = server1.invoke(() -> catchThrowable(() -> putDelta(TO_DELTA)));
+
+ assertThat(thrown).isInstanceOf(ArrayIndexOutOfBoundsException.class);
+ }
+
+ private int createServerCache() throws Exception {
+ cacheRule.createCache();
+
+ AttributesFactory af = new AttributesFactory();
+ af.setCloningEnabled(false);
+ af.setDataPolicy(DataPolicy.REPLICATE);
+ af.setScope(Scope.DISTRIBUTED_ACK);
+
+ cacheRule.getCache().createRegion(regionName, af.create());
+
+ CacheServer server = cacheRule.getCache().addCacheServer();
+ server.setPort(0);
+ // ensures updates to be sent instead of invalidates
+ server.setNotifyBySubscription(true);
+ server.start();
+ return server.getPort();
+ }
+
+ private void putDelta(DeltaFailure deltaFailure) {
+ Region region = cacheRule.getCache().getRegion(regionName);
+ deltaFailure.putInRegion(region);
+ }
+
+ enum DeltaFailure {
+ FROM_DELTA(new DeltaEOFException()), TO_DELTA(new FaultyDelta());
+
+ private final FaultyDelta value;
+
+ DeltaFailure(FaultyDelta value) {
+ this.value = value;
+ }
+
+ void putInRegion(Region region) {
+ for (int i = 0; i < PUT_COUNT; i++) {
+ value.setIntVal(i);
+ value.setBigObj(new byte[] {(byte) (i + 3), (byte) (i + 3)});
+ region.put("key", value);
+ }
+ }
+
+ }
+}
--
To stop receiving notification emails like this one, please contact
klund@apache.org.