Baggage { public static void discard() { current.remove(); } private  Baggage(); static void start(); static void discard(); static DetachedBaggage stop(); static void start(DetachedBaggage baggage); static DetachedBaggage swap(DetachedBaggage baggage); static void start(ByteString baggageBytes); static void start(byte[] baggageBytes); static void start(String base64Baggage); static DetachedBaggage fork(); static void join(DetachedBaggage otherBaggage); static void join(byte[] baggageBytes); static void join(ByteString baggageBytes); static void join(String base64baggage);  }
@Test public void testHas() { assertFalse(BaggageContents.contains(myname, ByteString.copyFrom("not-exist".getBytes()))); Baggage.discard(); try { assertFalse(BaggageContents.contains(myname, null)); assertFalse(BaggageContents.contains(myname, ByteString.copyFrom("not-exist".getBytes()))); BaggageContents.add(myname, ByteString.copyFrom("exist".getBytes()), ByteString.copyFrom("val".getBytes())); assertTrue(BaggageContents.contains(myname, ByteString.copyFrom("exist".getBytes()))); } finally { Baggage.discard(); } assertFalse(BaggageContents.contains(myname, ByteString.copyFrom("exist".getBytes()))); }
@Test public void testGetAndAdd() { assertTrue(BaggageContents.get(myname, ByteString.copyFrom("not-exist".getBytes())).isEmpty()); BaggageContents.add(myname, ByteString.copyFrom("exist".getBytes()), ByteString.copyFrom("val2".getBytes())); Baggage.discard(); try { assertTrue(BaggageContents.get(myname, ByteString.copyFrom("not-exist".getBytes())).isEmpty()); BaggageContents.add(myname, ByteString.copyFrom("exist".getBytes()), ByteString.copyFrom("val".getBytes())); BaggageContents .add(myname, ByteString.copyFrom("exist".getBytes()), ByteString.copyFrom("val2".getBytes())); assertTrue(BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).contains( ByteString.copyFrom("val".getBytes()))); assertTrue(BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).contains( ByteString.copyFrom("val2".getBytes()))); assertEquals(2, BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).size()); } finally { Baggage.discard(); } assertTrue(BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).isEmpty()); }
@Test public void testReplace() { assertTrue(BaggageContents.get(myname, ByteString.copyFrom("not-exist".getBytes())).isEmpty()); BaggageContents .replace(myname, ByteString.copyFrom("exist".getBytes()), ByteString.copyFrom("val2".getBytes())); Baggage.discard(); try { assertTrue(BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).isEmpty()); BaggageContents.add(myname, ByteString.copyFrom("exist".getBytes()), ByteString.copyFrom("val".getBytes())); BaggageContents.replace(myname, ByteString.copyFrom("exist".getBytes()), ByteString.copyFrom("val2".getBytes())); Set<ByteString> l = new HashSet<ByteString>(); l.add(ByteString.copyFrom("t1".getBytes())); l.add(ByteString.copyFrom("t2".getBytes())); BaggageContents.replace(myname, ByteString.copyFrom("exist".getBytes()), l); assertTrue(BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).contains( ByteString.copyFrom("t1".getBytes()))); assertTrue(BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).contains( ByteString.copyFrom("t2".getBytes()))); assertEquals(2, BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).size()); } finally { Baggage.discard(); } }
@Test public void testRemove() { BaggageContents.remove(myname, ByteString.copyFrom("exist".getBytes())); Baggage.discard(); try { assertTrue(BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).isEmpty()); BaggageContents.add(myname, ByteString.copyFrom("exist".getBytes()), ByteString.copyFrom("val".getBytes())); BaggageContents .add(myname, ByteString.copyFrom("exist2".getBytes()), ByteString.copyFrom("val".getBytes())); assertFalse(BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).isEmpty()); BaggageContents.remove(myname, ByteString.copyFrom("exist".getBytes())); assertTrue(BaggageContents.get(myname, ByteString.copyFrom("exist".getBytes())).isEmpty()); assertFalse(BaggageContents.get(myname, ByteString.copyFrom("exist2".getBytes())).isEmpty()); } finally { Baggage.discard(); } }