[ 
https://issues.apache.org/jira/browse/GEODE-2206?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15850622#comment-15850622
 ] 

ASF GitHub Bot commented on GEODE-2206:
---------------------------------------

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.


> Add junit-quickcheck to Gradle test dependencies.
> -------------------------------------------------
>
>                 Key: GEODE-2206
>                 URL: https://issues.apache.org/jira/browse/GEODE-2206
>             Project: Geode
>          Issue Type: Improvement
>            Reporter: Galen O'Sullivan
>            Assignee: Galen O'Sullivan
>
> Unit tests allow us to test cases we know about and have thought of. 
> Property-based testing allows us to test those, and some cases we haven't 
> thought of -- you're essentially fuzzing a limited subset of the code. 
> {{junit-quickcheck}} makes it easy to write "property-based" tests with 
> generators for the builtin types. You can also constrain input or build 
> custom generators for constrained data.
> I think this would be especially helpful for testing areas like PDX 
> serialization, which should be able to accept any serializable object a user 
> creates.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to