Created
June 9, 2017 08:26
-
-
Save purplefox/6de14775d331395ceeb01168367715f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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