/** * Run a task concurrently in 2 threads for 1 second. * * @param message the message * @param task the task * @throws Exception the first exception that is thrown (if any) */ public static void run(String message, Task task) throws Exception { run(message, task, 2, 1000); }
@Test public void test() throws Exception { Concurrent.run("cache", new Concurrent.Task() { @Override public void call() throws Exception { int k = value++ % 10; Data v = cache.get(k); Assert.assertEquals(k, v.value); } }); }
@Ignore("OAK-1599") @Test public void test() throws Exception { final AtomicInteger id = new AtomicInteger(); Concurrent.run("blob", new Concurrent.Task() { @Override public void call() throws Exception { int i = id.getAndIncrement(); ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.writeLong(out, i); out.write(EMPTY); byte[] data = out.toByteArray(); String id = store.writeBlob(new ByteArrayInputStream(data)); Assert.assertEquals(58, store.getBlobLength(id)); byte[] test = out.toByteArray(); Assert.assertEquals(8, store.readBlob(id, 0, test, 0, 8)); Assert.assertTrue(Arrays.equals(data, test)); } }); }