This is an automated email from the ASF dual-hosted git repository. jensdeppe pushed a commit to branch wip/corrupt-client in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/wip/corrupt-client by this push: new 898748a Export file apparently wants to be called *.gfd. 898748a is described below commit 898748a3528a19f711038aaeb5d44318e7262f5f Author: Jens Deppe <jde...@vmware.com> AuthorDate: Sat Nov 13 16:31:16 2021 -0800 Export file apparently wants to be called *.gfd. - Ensure fn is compatible with 9.8. --- .../org/apache/geode/ExportLocalDataFunction.java | 49 ++++++++++------------ .../geode/pdx/CorruptPdxClientServerDUnitTest.java | 30 +++++++------ .../apache/geode/pdx/internal/PdxWriterImpl.java | 1 + 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/geode-core/src/distributedTest/java/org/apache/geode/ExportLocalDataFunction.java b/geode-core/src/distributedTest/java/org/apache/geode/ExportLocalDataFunction.java index 3aac1c2..d7c1044 100644 --- a/geode-core/src/distributedTest/java/org/apache/geode/ExportLocalDataFunction.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/ExportLocalDataFunction.java @@ -22,11 +22,7 @@ import java.util.Arrays; import java.util.Map; import java.util.Properties; -import org.apache.logging.log4j.Logger; - -import org.apache.geode.LogWriter; import org.apache.geode.cache.Cache; -import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Declarable; import org.apache.geode.cache.Region; import org.apache.geode.cache.execute.Function; @@ -40,49 +36,48 @@ import org.apache.geode.cache.snapshot.SnapshotOptions.SnapshotFormat; import org.apache.geode.internal.cache.CachedDeserializable; import org.apache.geode.internal.cache.EntrySnapshot; import org.apache.geode.internal.cache.RegionEntry; -import org.apache.geode.logging.internal.log4j.api.LogService; -public class ExportLocalDataFunction implements Function<String>, Declarable { +public class ExportLocalDataFunction implements Function<Object[]>, Declarable { private static final long serialVersionUID = 4380042210718815441L; - private static final Logger logger = LogService.getLogger(); - public ExportLocalDataFunction() { - } + public ExportLocalDataFunction() {} - public void execute(final FunctionContext<String> context) { - logger.info("DEBUG: Executing ExportLocalDataFunction on {}", context.getMemberName()); + public void execute(final FunctionContext<Object[]> context) { + final Cache cache = context.getCache(); + final LogWriter logger = cache.getLogger(); - // Get file name parameter - final String fileName = context.getArguments(); + logger.info("EXPORT: Executing ExportLocalDataFunction on " + cache.getName()); - if (fileName == null) { - throw new IllegalArgumentException(getId() + " requires an export filename as parameter"); + Object[] arguments = context.getArguments(); + String directoryName = null; + if (arguments != null && arguments.length > 0) { + directoryName = (String) arguments[0]; } - final Cache cache = context.getCache(); - final String memberName = cache.getName(); - final LogWriter logger = cache.getLogger(); + final String memberName = context.getMemberName(); // Get local data set final RegionFunctionContext rfc = (RegionFunctionContext) context; final Region<Object, Object> localData = PartitionRegionHelper.getLocalDataForContext(rfc); // Create the file - final File file = new File(fileName); + final String fileName = + "server_" + memberName + "_region_" + localData.getName() + "_snapshot.gfd"; + final File file = new File(directoryName, fileName); // Export local data set final RegionSnapshotService<Object, Object> service = localData.getSnapshotService(); try { - logger.warning( + logger.warning("EXPORT: " + currentThread().getName() + ": Exporting " + localData.size() + " entries in region " - + localData.getName() + " to file " + file.getAbsolutePath() + " started"); + + localData.getName() + " to file " + file.getAbsolutePath() + " started"); final SnapshotOptions<Object, Object> options = service.createOptions(); options.setFilter(getRejectingFilter(localData, logger)); service.save(file, SnapshotFormat.GEMFIRE, options); - logger.warning( + logger.warning("EXPORT: " + currentThread().getName() + ": Exporting " + localData.size() + " entries in region " - + localData.getName() + " to file " + file.getAbsolutePath() + " completed"); + + localData.getName() + " to file " + file.getAbsolutePath() + " completed"); } catch (Exception e) { context.getResultSender().sendException(e); return; @@ -91,11 +86,12 @@ public class ExportLocalDataFunction implements Function<String>, Declarable { context.getResultSender().lastResult(true); } - private <K, V> SnapshotFilter<K, V> getRejectingFilter(final Region<K, V> localData, final LogWriter logger) { + private <K, V> SnapshotFilter<K, V> getRejectingFilter(final Region<K, V> localData, + final LogWriter logger) { return entry -> { boolean accept = true; try { - //noinspection ResultOfMethodCallIgnored + // noinspection ResultOfMethodCallIgnored entry.getValue(); } catch (Exception e) { final byte[] valueBytes = getValueBytes(entry); @@ -141,6 +137,5 @@ public class ExportLocalDataFunction implements Function<String>, Declarable { return false; } - public void init(Properties properties) { - } + public void init(Properties properties) {} } diff --git a/geode-core/src/distributedTest/java/org/apache/geode/pdx/CorruptPdxClientServerDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/pdx/CorruptPdxClientServerDUnitTest.java index 7b9f45a..89e2517 100644 --- a/geode-core/src/distributedTest/java/org/apache/geode/pdx/CorruptPdxClientServerDUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/pdx/CorruptPdxClientServerDUnitTest.java @@ -18,10 +18,8 @@ import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER; import static org.apache.geode.test.dunit.rules.ClusterStartupRule.getCache; import static org.apache.geode.test.dunit.rules.ClusterStartupRule.getClientCache; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import java.io.IOError; import java.io.IOException; import java.util.Properties; @@ -30,7 +28,6 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.apache.geode.ExportLocalDataFunction; -import org.apache.geode.cache.DataPolicy; import org.apache.geode.cache.Region; import org.apache.geode.cache.RegionShortcut; import org.apache.geode.cache.client.ClientCache; @@ -64,8 +61,12 @@ public class CorruptPdxClientServerDUnitTest { properties.put(SERIALIZABLE_OBJECT_FILTER, "org.apache.geode.**"); properties.put(LOCATORS, String.format("localhost[%d]", locatorPort)); - final MemberVM server1 = cluster.startServerVM(1, properties); - final MemberVM server2 = cluster.startServerVM(2, properties); + final MemberVM server1 = cluster.startServerVM(1, x -> x + .withProperties(properties) + .withPDXReadSerialized()); + final MemberVM server2 = cluster.startServerVM(2, x -> x + .withProperties(properties) + .withPDXReadSerialized()); final ClientVM client = cluster.startClientVM(3, cf -> cf.withLocatorConnection(locatorPort)); @@ -80,7 +81,8 @@ public class CorruptPdxClientServerDUnitTest { client.invoke(() -> { final ClientCache cache = getClientCache(); - final Region<Object, Object> region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create("testSimplePdx"); + final Region<Object, Object> region = + cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create("testSimplePdx"); region.put(1, new SimpleClass(1, (byte) 1)); region.put(2, new SimpleClass(2, (byte) 2)); PdxWriterImpl.breakIt = true; @@ -93,10 +95,12 @@ public class CorruptPdxClientServerDUnitTest { final SerializableRunnableIF checkValue = () -> { final Region<Object, Object> region = getServerRegion(); - assertThat(region.get(1)).isEqualTo(new SimpleClass(1, (byte) 1)); - assertThat(region.get(2)).isEqualTo(new SimpleClass(2, (byte) 2)); - assertThatThrownBy(() -> region.get(3)).hasRootCauseInstanceOf(IOException.class).hasRootCauseMessage("Unknown header byte 0"); - assertThatThrownBy(() -> region.get(4)).hasRootCauseInstanceOf(IOException.class).hasRootCauseMessage("Unknown header byte 0"); + // assertThat(region.get(1)).isEqualTo(new SimpleClass(1, (byte) 1)); + // assertThat(region.get(2)).isEqualTo(new SimpleClass(2, (byte) 2)); + assertThatThrownBy(() -> region.get(3)).hasRootCauseInstanceOf(IOException.class) + .hasRootCauseMessage("Unknown header byte 0"); + assertThatThrownBy(() -> region.get(4)).hasRootCauseInstanceOf(IOException.class) + .hasRootCauseMessage("Unknown header byte 0"); }; server1.invoke(checkValue); @@ -105,12 +109,12 @@ public class CorruptPdxClientServerDUnitTest { client.invoke(() -> { final Region<Object, Object> region = getClientCache().getRegion(REGION_NAME); ResultCollector resultCollector = FunctionService.onRegion(region) - .setArguments("/dev/null") + // .setArguments(new Object[] {"/dev/null"}) .execute(new ExportLocalDataFunction()); resultCollector.getResult(); -// region.remove(3); -// region.destroy(4); + region.remove(3); + region.destroy(4); }); } diff --git a/geode-core/src/main/java/org/apache/geode/pdx/internal/PdxWriterImpl.java b/geode-core/src/main/java/org/apache/geode/pdx/internal/PdxWriterImpl.java index 21160bb..9794aac 100644 --- a/geode-core/src/main/java/org/apache/geode/pdx/internal/PdxWriterImpl.java +++ b/geode-core/src/main/java/org/apache/geode/pdx/internal/PdxWriterImpl.java @@ -866,6 +866,7 @@ public class PdxWriterImpl implements PdxWriter { private HeapDataOutputStream.LongUpdater lu; public static volatile boolean breakIt = false; + private void writeHeader() { if (breakIt) { this.os.write((byte) 0);