Github user jaredjstewart commented on a diff in the pull request: https://github.com/apache/geode/pull/383#discussion_r99235354 --- Diff: geode-core/src/test/java/org/apache/geode/internal/InternalDataSerializerQuickcheckStringTest.java --- @@ -0,0 +1,63 @@ +/* + * 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; + +import static org.junit.Assert.*; + +import com.pholser.junit.quickcheck.Property; +import com.pholser.junit.quickcheck.runner.JUnitQuickcheck; +import org.apache.geode.DataSerializer; +import org.apache.geode.test.junit.categories.UnitTest; +import org.junit.Before; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * Tests the serialization and deserialization of randomly generated Strings. + * + * The current implementation (0.7 or 0.8alpha2) of junit-quickcheck-generators only generates valid + * codepoints, and that it doesn't tend to test strings that are particularly long, though the more + * trials you run, the longer they get. + */ +@Category(UnitTest.class) +@RunWith(JUnitQuickcheck.class) +public class InternalDataSerializerQuickcheckStringTest { + @Property(trials = 1000) + public void StringSerializedDeserializesToSameValue(String originalString) throws IOException { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); + + DataSerializer.writeString(originalString, dataOutputStream); + dataOutputStream.flush(); + + byte[] stringBytes = byteArrayOutputStream.toByteArray(); + DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(stringBytes)); + String returnedString = DataSerializer.readString(dataInputStream); + + assertEquals("Deserialized string matches original", originalString, returnedString); + } + + @Before + public void setUp() { + // this may be unnecessary, but who knows what tests run before us. + InternalDataSerializer.reinitialize(); --- End diff -- If the goal here is to protect against tests that ran before this, you may want to use `@BeforeClass` instead of `@Before` so that only gets invoked once for the class, rather than for each of the (1000) trials.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---