public void testClear() { Recycler<byte[]> r = newRecycler(); Recycler.V<byte[]> o = r.obtain(); getRandom().nextBytes(o.v()); o.release(); o = r.obtain(); for (int i = 0; i < o.v().length; ++i) { assertEquals(0, o.v()[i]); } o.release(); r.close(); }
public void testDoubleRelease() { final Recycler<byte[]> r = newRecycler(); final Recycler.V<byte[]> v1 = r.obtain(); v1.release(); try { v1.release(); } catch (ElasticsearchIllegalStateException e) { // impl has protection against double release: ok return; } // otherwise ensure that the impl may not be returned twice final Recycler.V<byte[]> v2 = r.obtain(); final Recycler.V<byte[]> v3 = r.obtain(); assertNotSame(v2.v(), v3.v()); r.close(); }
public void testReuse() { Recycler<byte[]> r = newRecycler(); Recycler.V<byte[]> o = r.obtain(); assertFalse(o.isRecycled()); final byte[] b1 = o.v(); o.release(); o = r.obtain(); final byte[] b2 = o.v(); if (o.isRecycled()) { assertSame(b1, b2); } else { assertNotSame(b1, b2); } o.release(); r.close(); }