Skip to content

Instantly share code, notes, and snippets.

@purplefox
Created June 9, 2017 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purplefox/6de14775d331395ceeb01168367715f4 to your computer and use it in GitHub Desktop.
Save purplefox/6de14775d331395ceeb01168367715f4 to your computer and use it in GitHub Desktop.
@Test
@Repeat(times=1000)
public void testAsyncFileConcurrency() throws Exception {
String fileName = "some-file.dat";
AtomicReference<AsyncFile> arFile = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
vertx.fileSystem().open(testDir + pathSep + fileName, new OpenOptions(), ar -> {
if (ar.succeeded()) {
AsyncFile af = ar.result();
arFile.set(af);
} else {
fail(ar.cause().getMessage());
}
latch.countDown();
});
awaitLatch(latch);
AsyncFile af = arFile.get();
Buffer buff = Buffer.buffer(randomByteArray(4096));
for (int i = 0; i < 100000; i++) {
af.write(buff);
}
af.close(onSuccess(v -> {
testComplete();
}));
await();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment