changeset 223:bda9fbee58c8

Make StringBu* tests more resilient.
author shade
date Wed, 21 Oct 2015 20:35:44 +0300
parents e7361050c369
children d0c6cd011ea0
files jcstress-core/src/main/java/org/openjdk/jcstress/infra/results/StringResult1.java tests-custom/src/main/java/org/openjdk/jcstress/tests/strings/StringBufferTest.java tests-custom/src/main/java/org/openjdk/jcstress/tests/strings/StringBuilderTest.java
diffstat 3 files changed, 90 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/results/StringResult1.java	Wed Oct 21 20:35:44 2015 +0300
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jcstress.infra.results;
+
+import org.openjdk.jcstress.annotations.Result;
+import sun.misc.Contended;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+@Result
+public class StringResult1 implements Serializable {
+
+    @Contended
+    public String r1;
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        StringResult1 that = (StringResult1) o;
+
+        if (r1 != null ? !r1.equals(that.r1) : that.r1 != null) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return r1 != null ? r1.hashCode() : 0;
+    }
+
+    @Override
+    public String toString() {
+        return "[" + r1 + ']';
+    }
+
+}
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/strings/StringBufferTest.java	Tue Oct 20 22:23:40 2015 +0300
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/strings/StringBufferTest.java	Wed Oct 21 20:35:44 2015 +0300
@@ -29,21 +29,24 @@
 
 @JCStressTest
 @Description("Tests the StringBuffers are working good under concurrent updates.")
-@Outcome(id = "[fb]", expect = Expect.ACCEPTABLE, desc = "T1 -> T2 execution.")
-@Outcome(id = "[bf]", expect = Expect.ACCEPTABLE, desc = "T2 -> T1 execution.")
+@Outcome(id = "[bbbbbbbbbbbbbbbbbbbb]", expect = Expect.ACCEPTABLE, desc = "All appends are visible")
 @State
 public class StringBufferTest {
 
-    StringBuffer sb = new StringBuffer();
+    StringBuffer sb = new StringBuffer(0);
 
     @Actor
     public void actor1() {
-        sb.append('f');
+        for (int i = 0; i < 10; ++i) {
+            sb.append('b');
+        }
     }
 
     @Actor
     public void actor2() {
-        sb.append('b');
+        for (int i = 0; i < 10; ++i) {
+            sb.append('b');
+        }
     }
 
     @Arbiter
--- a/tests-custom/src/main/java/org/openjdk/jcstress/tests/strings/StringBuilderTest.java	Tue Oct 20 22:23:40 2015 +0300
+++ b/tests-custom/src/main/java/org/openjdk/jcstress/tests/strings/StringBuilderTest.java	Wed Oct 21 20:35:44 2015 +0300
@@ -29,27 +29,42 @@
 
 @JCStressTest
 @Description("Tests the StringBuilders are working good under concurrent updates.")
-@Outcome(id = "[fb]", expect = Expect.ACCEPTABLE, desc = "T1 -> T2 execution.")
-@Outcome(id = "[bf]", expect = Expect.ACCEPTABLE, desc = "T2 -> T1 execution.")
+@Outcome(id = "[bbbbbbbbbbbbbbbbbbbb]", expect = Expect.ACCEPTABLE, desc = "All appends are visible.")
 @Outcome(expect = Expect.ACCEPTABLE_INTERESTING, desc = "Other values are expected, threads are messing with each other.")
 @State
 public class StringBuilderTest {
 
-    StringBuilder sb = new StringBuilder();
+    StringBuilder sb = new StringBuilder(0);
 
     @Actor
     public void actor1() {
-        sb.append('f');
+        try {
+            for (int i = 0; i < 10; ++i) {
+                sb.append('b');
+            }
+        } catch (Exception e) {
+            // most probably AIOOBE, expected for this test
+        }
     }
 
     @Actor
     public void actor2() {
-        sb.append('b');
+        try {
+            for (int i = 0; i < 10; ++i) {
+                sb.append('b');
+            }
+        } catch (Exception e) {
+            // most probably AIOOBE, expected for this test
+        }
     }
 
     @Arbiter
     public void tester(StringResult1 r) {
-        r.r1 = sb.toString();
+        try {
+            r.r1 = sb.toString();
+        } catch (Exception e) {
+            r.r1 = "<ERROR>";
+        }
     }
 
 }