@Test public void testMultipleIDDemand() { final ElementBuilder eb = new SynchronizedElementBuilder(new DefaultElementBuilder()); int nbThreads = 10; final int nbAllocs = 1000; final int[] used = new int[nbThreads * nbAllocs]; Thread[] ths = new Thread[nbThreads]; for (int i = 0; i < nbThreads; i++) { Thread t = new Thread(() -> { for (int x = 0; x < nbAllocs; x++) { VM v = eb.newVM(); used[v.id()]++; } }); ths[i] = t; t.start(); } try { for (int i = 0; i < nbThreads; i++) { ths[i].join(); } } catch (InterruptedException ex) { Assert.fail(ex.getMessage(), ex); } for (int i = 0; i < used.length; i++) { if (used[i] != 1) { Assert.fail("ID '" + i + "' used " + used[i] + " times"); } } }
@Override public VM newVM() { synchronized (vmLock) { return base.newVM(); } }
SynchronizedElementBuilder implements ElementBuilder { @Override public VM newVM() { synchronized (vmLock) { return base.newVM(); } } }
SynchronizedElementBuilder implements ElementBuilder { @Override public VM newVM() { synchronized (vmLock) { return base.newVM(); } } SynchronizedElementBuilder(ElementBuilder b); }
SynchronizedElementBuilder implements ElementBuilder { @Override public VM newVM() { synchronized (vmLock) { return base.newVM(); } } SynchronizedElementBuilder(ElementBuilder b); @Override VM newVM(); @Override VM newVM(int id); @Override Node newNode(); @Override Node newNode(int id); @Override boolean contains(VM v); @Override boolean contains(Node n); @Override ElementBuilder copy(); }
SynchronizedElementBuilder implements ElementBuilder { @Override public VM newVM() { synchronized (vmLock) { return base.newVM(); } } SynchronizedElementBuilder(ElementBuilder b); @Override VM newVM(); @Override VM newVM(int id); @Override Node newNode(); @Override Node newNode(int id); @Override boolean contains(VM v); @Override boolean contains(Node n); @Override ElementBuilder copy();  }