< prev index next >

test/jdk/java/util/concurrent/ConcurrentLinkedQueue/WhiteBox.java

Print this page
8197531: Miscellaneous changes imported from jsr166 CVS 2018-04
Reviewed-by: martin, psandoz


 321             return bos.toByteArray();
 322         } catch (Exception fail) {
 323             throw new AssertionError(fail);
 324         }
 325     }
 326 
 327     @SuppressWarnings("unchecked")
 328     <T> T serialClone(T o) {
 329         try {
 330             ObjectInputStream ois = new ObjectInputStream
 331                 (new ByteArrayInputStream(serialBytes(o)));
 332             T clone = (T) ois.readObject();
 333             assertNotSame(o, clone);
 334             assertSame(o.getClass(), clone.getClass());
 335             return clone;
 336         } catch (Exception fail) {
 337             throw new AssertionError(fail);
 338         }
 339     }
 340 

 341     public void testSerialization() {
 342         ConcurrentLinkedQueue q = serialClone(new ConcurrentLinkedQueue());
 343         assertInvariants(q);
 344     }
 345 
 346     /** Checks conditions which should always be true. */
 347     void assertInvariants(ConcurrentLinkedQueue q) {
 348         assertNotNull(head(q));
 349         assertNotNull(tail(q));
 350         // head is never self-linked (but tail may!)
 351         for (Object h; next(h = head(q)) == h; )
 352             assertNotSame(h, head(q)); // must be update race
 353     }
 354 }


 321             return bos.toByteArray();
 322         } catch (Exception fail) {
 323             throw new AssertionError(fail);
 324         }
 325     }
 326 
 327     @SuppressWarnings("unchecked")
 328     <T> T serialClone(T o) {
 329         try {
 330             ObjectInputStream ois = new ObjectInputStream
 331                 (new ByteArrayInputStream(serialBytes(o)));
 332             T clone = (T) ois.readObject();
 333             assertNotSame(o, clone);
 334             assertSame(o.getClass(), clone.getClass());
 335             return clone;
 336         } catch (Exception fail) {
 337             throw new AssertionError(fail);
 338         }
 339     }
 340 
 341     @Test
 342     public void testSerialization() {
 343         ConcurrentLinkedQueue q = serialClone(new ConcurrentLinkedQueue());
 344         assertInvariants(q);
 345     }
 346 
 347     /** Checks conditions which should always be true. */
 348     void assertInvariants(ConcurrentLinkedQueue q) {
 349         assertNotNull(head(q));
 350         assertNotNull(tail(q));
 351         // head is never self-linked (but tail may!)
 352         for (Object h; next(h = head(q)) == h; )
 353             assertNotSame(h, head(q)); // must be update race
 354     }
 355 }
< prev index next >