@Test public void testReleaseNullBuffer() throws Exception { boolean failed = false; try { AsynchronousFileImpl.destroyBuffer(null); } catch (Exception expected) { failed = true; } assertTrue("Exception expected", failed); }
@Override public void run() { super.run(); ByteBuffer buffer = null; synchronized (MultiThreadAsynchronousFileTest.class) { buffer = AsynchronousFileImpl.newBuffer(MultiThreadAsynchronousFileTest.SIZE); } try { // I'm always reusing the same buffer, as I don't want any noise from // malloc on the measurement // Encoding buffer MultiThreadAsynchronousFileTest.addString( "Thread name=" + Thread.currentThread().getName() + ";" + "\n", buffer); for (int local = buffer.position(); local < buffer.capacity() - 1; local++) { buffer.put((byte) ' '); } buffer.put((byte) '\n'); latchStart.countDown(); latchStart.await(); CountDownLatch latchFinishThread = null; if (!sync) { latchFinishThread = new CountDownLatch(MultiThreadAsynchronousFileTest.NUMBER_OF_LINES); } LinkedList<CountDownCallback> list = new LinkedList<CountDownCallback>(); for (int i = 0; i < MultiThreadAsynchronousFileTest.NUMBER_OF_LINES; i++) { if (sync) { latchFinishThread = new CountDownLatch(1); } CountDownCallback callback = new CountDownCallback(latchFinishThread, null, null, 0); if (!sync) { list.add(callback); } addData(libaio, buffer, callback); if (sync) { latchFinishThread.await(); Assert.assertTrue(callback.doneCalled); Assert.assertFalse(callback.errorCalled != 0); } } if (!sync) { latchFinishThread.await(); } for (CountDownCallback callback : list) { Assert.assertTrue(callback.doneCalled); Assert.assertFalse(callback.errorCalled != 0); } for (CountDownCallback callback : list) { Assert.assertTrue(callback.doneCalled); Assert.assertFalse(callback.errorCalled != 0); } } catch (Throwable e) { e.printStackTrace(); failed = e; } finally { synchronized (MultiThreadAsynchronousFileTest.class) { AsynchronousFileImpl.destroyBuffer(buffer); } } }
public void bufferDone(final ByteBuffer buffer1) { AsynchronousFileImpl.destroyBuffer(buffer1); }
private static final void destroy(ByteBuffer buffer0) { if (buffer0 != null) { AsynchronousFileImpl.destroyBuffer(buffer0); } }