コード例 #1
0
 @Test
 public void releaseShouldAddKryoToPool() {
   assertEquals(0, size());
   Kryo kryo = pool.borrow();
   pool.release(kryo);
   assertEquals(1, size());
 }
コード例 #2
0
 @Test
 public void testSize() {
   assertEquals(0, size());
   Kryo kryo1 = pool.borrow();
   assertEquals(0, size());
   Kryo kryo2 = pool.borrow();
   assertFalse(kryo1 == kryo2);
   pool.release(kryo1);
   assertEquals(1, size());
   pool.release(kryo2);
   assertEquals(2, size());
 }
コード例 #3
0
 @Test(expected = IllegalArgumentException.class)
 public void runWithKryoShouldRethrowException() {
   String value =
       pool.run(
           new KryoCallback<String>() {
             @Override
             public String execute(Kryo kryo) {
               throw new IllegalArgumentException();
             }
           });
 }
コード例 #4
0
 @Test
 public void runWithKryoShouldReturnResult() {
   String value =
       pool.run(
           new KryoCallback<String>() {
             @Override
             public String execute(Kryo kryo) {
               return "foo";
             }
           });
   assertEquals("foo", value);
 }
コード例 #5
0
 @Test
 public void runWithKryoShouldAddKryoToPool() {
   assertEquals(0, size());
   pool.run(
       new KryoCallback<String>() {
         @Override
         public String execute(Kryo kryo) {
           return null;
         }
       });
   assertEquals(1, size());
 }
コード例 #6
0
 @Test
 public void runWithKryoShouldAddKryoToPoolOnException() {
   assertEquals(0, size());
   try {
     pool.run(
         new KryoCallback<String>() {
           @Override
           public String execute(Kryo kryo) {
             throw new RuntimeException();
           }
         });
     fail("Exception should be rethrown.");
   } catch (RuntimeException e) {
     // expected
   }
   assertEquals(1, size());
 }
コード例 #7
0
 @Test
 public void getShouldReturnAvailableInstance() {
   Kryo kryo = pool.borrow();
   pool.release(kryo);
   assertTrue(kryo == pool.borrow());
 }