Let each thread compute the same value ConcurrentComputed259132
authorJaroslav Tulach <jtulach@netbeans.org>
Wed, 11 May 2016 05:33:53 +0200
branchConcurrentComputed259132
changeset 1089b2a7f7e26276
parent 1088 0f5f964766b3
child 1090 413753a14753
Let each thread compute the same value
json/src/test/java/org/netbeans/html/json/impl/ParallelChangeTest.java
     1.1 --- a/json/src/test/java/org/netbeans/html/json/impl/ParallelChangeTest.java	Thu May 05 05:18:04 2016 +0200
     1.2 +++ b/json/src/test/java/org/netbeans/html/json/impl/ParallelChangeTest.java	Wed May 11 05:33:53 2016 +0200
     1.3 @@ -79,28 +79,28 @@
     1.4  
     1.5      private void doTest(boolean multipleValues) throws InterruptedException {
     1.6          class Test implements Runnable {
     1.7 -            final int index;
     1.8 +            final int offset;
     1.9              final Depending dep;
    1.10 -            private RuntimeException runtimeException;
    1.11 +            private Error error;
    1.12  
    1.13              public Test(int index, Depending dep) {
    1.14 -                this.index = index;
    1.15 +                this.offset = index;
    1.16                  this.dep = dep;
    1.17              }
    1.18  
    1.19              @Override
    1.20              public void run() {
    1.21                  try {
    1.22 -                    int value = dep.getPlus();
    1.23 -                    assertEquals(value, index + 11);
    1.24 -                } catch (RuntimeException ex) {
    1.25 -                    this.runtimeException = ex;
    1.26 +                    int value = dep.getValuePlusAdd();
    1.27 +                    assertEquals(value, offset + 11, "Offset " + offset + " plus one plus ten");
    1.28 +                } catch (Error err) {
    1.29 +                    this.error = err;
    1.30                  }
    1.31              }
    1.32  
    1.33              private void assertException() {
    1.34 -                if (runtimeException != null) {
    1.35 -                    throw runtimeException;
    1.36 +                if (error != null) {
    1.37 +                    throw error;
    1.38                  }
    1.39              }
    1.40          }
    1.41 @@ -117,8 +117,8 @@
    1.42                  values[i] = i == 0 ? new BlockingValue() : values[0];
    1.43              }
    1.44              BlockingValueCntrl.initialize(blockInCall);
    1.45 -            deps[i] = new Depending(i, values[i]);
    1.46 -            runs[i] = new Test(i, deps[i]);
    1.47 +            deps[i] = new Depending(10, values[i]);
    1.48 +            runs[i] = new Test(0, deps[i]);
    1.49              exec.execute(runs[i]);
    1.50          }
    1.51  
    1.52 @@ -127,7 +127,7 @@
    1.53          for (int i = 0; i < deps.length; i++) {
    1.54              runs[i].assertException();
    1.55              values[i].setValue(30);
    1.56 -            assertEquals(deps[i].getPlus(), i + 42);
    1.57 +            assertEquals(deps[i].getValuePlusAdd(), 41, "[" + i + "] = 0 plus 30 plus one plus 10");
    1.58          }
    1.59      }
    1.60  
    1.61 @@ -159,8 +159,8 @@
    1.62      })
    1.63      static class DependingCntrl {
    1.64          @ComputedProperty
    1.65 -        static int plus(BlockingValue dep, int add) {
    1.66 -            return dep.getPlusOne() + 10;
    1.67 +        static int valuePlusAdd(BlockingValue dep, int add) {
    1.68 +            return dep.getPlusOne() + add;
    1.69          }
    1.70      }
    1.71