-
Notifications
You must be signed in to change notification settings - Fork 686
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-9204: thread hung waiting for response (#6426)
Co-authored-by: Bruce Schuchardt <[email protected]>
- Loading branch information
1 parent
b07f320
commit 19f55ad
Showing
6 changed files
with
172 additions
and
19 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
...c/distributedTest/java/org/apache/geode/distributed/internal/BadCacheLoaderDUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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.distributed.internal; | ||
|
||
import java.io.NotSerializableException; | ||
import java.io.Serializable; | ||
import java.util.Properties; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import org.apache.geode.InternalGemFireException; | ||
import org.apache.geode.cache.Cache; | ||
import org.apache.geode.cache.Region; | ||
import org.apache.geode.cache.RegionShortcut; | ||
import org.apache.geode.distributed.ConfigurationProperties; | ||
import org.apache.geode.test.dunit.VM; | ||
import org.apache.geode.test.dunit.rules.CacheRule; | ||
import org.apache.geode.test.dunit.rules.DistributedRule; | ||
|
||
public class BadCacheLoaderDUnitTest implements Serializable { | ||
public static final String TEST_REGION = "testRegion"; | ||
public static final String TEST_KEY = "testKey"; | ||
public static final String TEST_VALUE = "testValue"; | ||
|
||
static class NotSerializableTestException extends RuntimeException { | ||
Object unserializableField = new Object(); | ||
} | ||
|
||
@Rule | ||
public DistributedRule distributedRule = new DistributedRule(2); | ||
|
||
@Rule | ||
public CacheRule cacheRule = CacheRule.builder().build(); | ||
|
||
/** | ||
* Ensure that a cache loader throwing an exception that is not serializable is handled | ||
* correctly | ||
*/ | ||
@Test | ||
public void testNonSerializableObjectReturnedByCacheLoader() throws Exception { | ||
final VM cacheLoaderVM = VM.getVM(0); | ||
final VM fetchingVM = VM.getVM(1); | ||
|
||
final Properties properties = new Properties(); | ||
properties.put(ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER, | ||
NotSerializableTestException.class.getName()); | ||
|
||
cacheLoaderVM.invoke("create a region with a bad cache loader", | ||
() -> createRegionWithBadCacheLoader(properties)); | ||
|
||
Assertions.assertThatThrownBy(() -> fetchingVM.invoke("fetch something from the cache", | ||
() -> fetchValueCausingCacheLoad(properties))) | ||
.hasCauseInstanceOf(InternalGemFireException.class) | ||
.hasRootCauseInstanceOf(NotSerializableException.class) | ||
.hasRootCauseMessage("java.lang.Object"); | ||
} | ||
|
||
private void fetchValueCausingCacheLoad(Properties properties) { | ||
final Cache cache = cacheRule.getOrCreateCache(properties); | ||
final Region<String, Object> testRegion = | ||
cache.<String, Object>createRegionFactory(RegionShortcut.PARTITION) | ||
.setCacheLoader(helper -> new Object()) | ||
.create(TEST_REGION); | ||
testRegion.getAttributesMutator().setCacheLoader(helper -> "should not be invoked"); | ||
testRegion.get(TEST_KEY); | ||
} | ||
|
||
private void createRegionWithBadCacheLoader(Properties properties) { | ||
final Cache cache = cacheRule.getOrCreateCache(properties); | ||
final Region<String, Object> testRegion = | ||
cache.<String, Object>createRegionFactory(RegionShortcut.PARTITION) | ||
.setCacheLoader(helper -> { | ||
throw new NotSerializableTestException(); | ||
}) | ||
.create(TEST_REGION); | ||
testRegion.put(TEST_KEY, TEST_VALUE); | ||
testRegion.destroy(TEST_KEY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
geode-core/src/test/java/org/apache/geode/distributed/internal/ReplyMessageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.distributed.internal; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.DataInputStream; | ||
import java.io.NotSerializableException; | ||
|
||
import org.junit.Test; | ||
|
||
import org.apache.geode.internal.HeapDataOutputStream; | ||
import org.apache.geode.internal.InternalDataSerializer; | ||
|
||
public class ReplyMessageTest { | ||
@Test | ||
public void replyMessageCanSerializeWithNonSerializableValue() throws Exception { | ||
final ReplyMessage replyMessage = new ReplyMessage(); | ||
replyMessage.setReturnValue(new Object()); | ||
final HeapDataOutputStream heapDataOutputStream = new HeapDataOutputStream(1000); | ||
InternalDataSerializer.getDSFIDSerializer().invokeToData(replyMessage, heapDataOutputStream); | ||
final byte[] bytes = heapDataOutputStream.toByteArray(); | ||
final DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes)); | ||
final ReplyMessage newReplyMessage = new ReplyMessage(); | ||
InternalDataSerializer.getDSFIDSerializer().invokeFromData(newReplyMessage, dataInputStream); | ||
assertThat(newReplyMessage.getException()).hasCauseInstanceOf( | ||
NotSerializableException.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters