Assign the models to map context ConcurrentComputed259132
authorJaroslav Tulach <jtulach@netbeans.org>
Wed, 11 May 2016 05:56:31 +0200
branchConcurrentComputed259132
changeset 1090413753a14753
parent 1089 b2a7f7e26276
child 1091 9c7413573b98
Assign the models to map context
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	Wed May 11 05:33:53 2016 +0200
     1.2 +++ b/json/src/test/java/org/netbeans/html/json/impl/ParallelChangeTest.java	Wed May 11 05:56:31 2016 +0200
     1.3 @@ -49,6 +49,7 @@
     1.4  import net.java.html.BrwsrCtx;
     1.5  import net.java.html.json.ComputedProperty;
     1.6  import net.java.html.json.Model;
     1.7 +import net.java.html.json.Models;
     1.8  import net.java.html.json.Property;
     1.9  import org.netbeans.html.context.spi.Contexts;
    1.10  import org.netbeans.html.json.spi.Technology;
    1.11 @@ -112,13 +113,15 @@
    1.12          ExecutorService exec = Executors.newFixedThreadPool(deps.length);
    1.13          for (int i = 0; i < deps.length; i++) {
    1.14              if (multipleValues) {
    1.15 -                values[i] = new BlockingValue();
    1.16 +                values[i] = BlockingValueCntrl.create(c);
    1.17              } else {
    1.18 -                values[i] = i == 0 ? new BlockingValue() : values[0];
    1.19 +                values[i] = i == 0 ? BlockingValueCntrl.create(c) : values[0];
    1.20              }
    1.21 -            BlockingValueCntrl.initialize(blockInCall);
    1.22 -            deps[i] = new Depending(10, values[i]);
    1.23 +            deps[i] = DependingCntrl.create(c, values[i], 10);
    1.24              runs[i] = new Test(0, deps[i]);
    1.25 +        }
    1.26 +        BlockingValueCntrl.initialize(blockInCall);
    1.27 +        for (int i = 0; i < deps.length; i++) {
    1.28              exec.execute(runs[i]);
    1.29          }
    1.30  
    1.31 @@ -143,14 +146,20 @@
    1.32  
    1.33          @ComputedProperty
    1.34          static int plusOne(int value)  {
    1.35 -            latch.countDown();
    1.36 -            try {
    1.37 -                latch.await();
    1.38 -            } catch (InterruptedException ex) {
    1.39 -                throw new IllegalStateException(ex);
    1.40 +            if (latch != null) {
    1.41 +                latch.countDown();
    1.42 +                try {
    1.43 +                    latch.await();
    1.44 +                } catch (InterruptedException ex) {
    1.45 +                    throw new IllegalStateException(ex);
    1.46 +                }
    1.47              }
    1.48              return value + 1;
    1.49          }
    1.50 +
    1.51 +        static BlockingValue create(BrwsrCtx c) {
    1.52 +            return Models.bind(new BlockingValue(), c);
    1.53 +        }
    1.54      }
    1.55  
    1.56      @Model(className = "Depending", properties = {
    1.57 @@ -162,6 +171,12 @@
    1.58          static int valuePlusAdd(BlockingValue dep, int add) {
    1.59              return dep.getPlusOne() + add;
    1.60          }
    1.61 +
    1.62 +        static Depending create(BrwsrCtx c, BlockingValue value, int add) {
    1.63 +            Depending d = Models.bind(new Depending(add, null), c);
    1.64 +            d.setDep(value);
    1.65 +            return d;
    1.66 +        }
    1.67      }
    1.68  
    1.69  }