@Override public synchronized void addListener (Object key, SpaceListener listener, long timeout) { getSL().out (key, listener, timeout); }
@Override public synchronized void addListener (Object key, SpaceListener listener) { getSL().out (key, listener); }
public synchronized void addListener (Object key, SpaceListener listener, long timeout) { getSL().out (key, listener, timeout); } public synchronized void removeListener
public void run() { ISOUtil.sleep(1000L); sp.out("KA", Boolean.TRUE); } }.start();
@Test public void testDump() throws Throwable { TSpace tSpace = new TSpace(); tSpace.out("", "testString"); tSpace.out(Integer.valueOf(0), Integer.valueOf(-1)); tSpace.out(Integer.valueOf(31), ""); PrintStream p = new PrintStream(new ByteArrayOutputStream(), true); tSpace.dump(p, "testTSpaceIndent"); assertEquals("tSpace.entries.size()", 3, tSpace.entries.size()); }
@Test public void testOut() throws Throwable { TSpace sp = mock(TSpace.class); SpaceInterceptor spaceInterceptor = new SpaceInterceptor(sp); sp.out("testString", "1", 0L); spaceInterceptor.out("testString", "1", 0L); assertSame("spaceInterceptor.sp", sp, spaceInterceptor.sp); verify(sp, times(2)).out("testString", "1", 0L); }
@SuppressWarnings("unchecked") @Test public void testInp1() throws Throwable { TSpace tSpace = new TSpace(); tSpace.out("", "testString"); tSpace.out(Integer.valueOf(0), Integer.valueOf(-1)); tSpace.out(Integer.valueOf(31), Integer.valueOf(-32), 100L); tSpace.inp(new MD5Template("", (Object) null)); tSpace.out("", "", 1000L); String result = (String) tSpace.inp(""); assertEquals("tSpace.entries.get(\"\").size()", 1, ((List) tSpace.entries.get("")).size()); assertFalse("tSpace.entries.get(\"\").get(0) had \"testString\" removed", "testString".equals(((List) tSpace.entries.get("")).get(0))); assertEquals("result", "testString", result); assertEquals("tSpace.entries.size()", 3, tSpace.entries.size()); }
@Test public void testOut() throws Throwable { TSpace tSpace = new TSpace(); tSpace.out(Integer.valueOf(0), "testString", 100L); assertEquals("tSpace.entries.size()", 1, tSpace.entries.size()); }
@Test public void testNRD() { long now = System.currentTimeMillis(); sp.out("NRD", "NRDTEST", 1000L); sp.nrd("NRD"); long elapsed = System.currentTimeMillis() - now; assertTrue("Invalid elapsed time " + elapsed, elapsed >= 1000L); } @Test
@Test public void testMultiKeyLoad() throws Exception { String s = "The quick brown fox jumped over the lazy dog"; Profiler prof = new Profiler(); for (int i = 0; i < COUNT; i++) { sp.out("testMultiKeyLoad_Key" + Integer.toString(i), s, 60000); } // prof.dump (System.err, "MultiKeyLoad out >"); prof = new Profiler(); for (int i = 0; i < COUNT; i++) { assertTrue(s.equals(sp.in("testMultiKeyLoad_Key" + Integer.toString(i)))); } // prof.dump (System.err, "MultiKeyLoad in >"); }
@Test public void testNRDWithDelay() { long now = System.currentTimeMillis(); sp.out("NRD", "NRDTEST", 1000L); Object obj = sp.nrd("NRD", 500L); assertNotNull("Object should not be null", obj); obj = sp.nrd("NRD", 5000L); long elapsed = System.currentTimeMillis() - now; assertTrue("Invalid elapsed time " + elapsed, elapsed >= 1000L && elapsed <= 2000L); assertNull("Object should be null", obj); } public void notify(Object key, Object value) {
@Test public void testExpiration() { sp.out("testExpiration_Key", "ABC", 50); assertEquals("ABC", sp.rdp("testExpiration_Key")); try { Thread.sleep(60); } catch (InterruptedException e) { } assertNull("ABC", sp.rdp("testExpiration_Key")); }
@Test public void testGC() throws Exception { sp.out("testGC_Key", "ABC", 50); sp.out("testGC_Key", "XYZ", 50); assertEquals("ABC", sp.rdp("testGC_Key")); try { Thread.sleep(60); } catch (InterruptedException e) { } assertEquals("testGC_Key", sp.getKeysAsString()); sp.gc(); assertEquals("", sp.getKeysAsString()); sp.gc(); }
@Test public void testExist() { sp.out("KEYA", Boolean.TRUE); sp.out("KEYB", Boolean.TRUE); assertTrue("existAny ([KEYA])", sp.existAny(new String[] { "KEYA" })); assertTrue("existAny ([KEYB])", sp.existAny(new String[] { "KEYB" })); assertTrue("existAny ([KEYA,KEYB])", sp.existAny(new String[] { "KEYA", "KEYB" })); assertFalse("existAny ([KEYC,KEYD])", sp.existAny(new String[] { "KEYC", "KEYD" })); }
@Test public void testOutRdpInpRdp() throws Exception { Object o = Boolean.TRUE; String k = "testOutRdpInpRdp_Key"; sp.out(k, o); assertTrue(o.equals(sp.rdp(k))); assertTrue(o.equals(sp.rd(k))); assertTrue(o.equals(sp.rd(k, 1000))); assertTrue(o.equals(sp.inp(k))); assertNull(sp.rdp(k)); assertNull(sp.rd(k, 100)); }
@Test public void testSingleKeyLoad() throws Exception { String s = "The quick brown fox jumped over the lazy dog"; String k = "testSingleKeyLoad_SingleKey"; Profiler prof = new Profiler(); for (int i = 0; i < COUNT; i++) { sp.out(k, s, 60000); } // prof.dump (System.err, "SingleKeyLoad out >"); prof = new Profiler(); for (int i = 0; i < COUNT; i++) { assertTrue(s.equals(sp.in(k))); } // prof.dump (System.err, "SingleKeyLoad in >"); assertNull(sp.rdp(k)); }
@Test public void testNullEntry() { try { sp.out("testNull", null); fail("NullPointerException should have been called"); } catch (NullPointerException e) { assertNull("Verify null entry (rdp)", sp.rdp("testNull")); assertNull("Verify null entry (inp)", sp.inp("testNull")); } }
@Test public void testSimpleOut() { sp.out("testSimpleOut_Key", "ABC"); sp.out("testSimpleOut_Key", "XYZ"); assertEquals("ABC", sp.rdp("testSimpleOut_Key")); assertEquals("ABC", sp.inp("testSimpleOut_Key")); assertEquals("XYZ", sp.rdp("testSimpleOut_Key")); assertEquals("XYZ", sp.inp("testSimpleOut_Key")); assertNull(sp.rdp("Test")); assertNull(sp.inp("Test")); }
@Test public void testPush() { sp.push("PUSH", "ONE"); sp.push("PUSH", "TWO"); sp.push("PUSH", "THREE"); sp.out("PUSH", "FOUR"); assertEquals("THREE", sp.rdp("PUSH")); assertEquals("THREE", sp.inp("PUSH")); assertEquals("TWO", sp.inp("PUSH")); assertEquals("ONE", sp.inp("PUSH")); assertEquals("FOUR", sp.inp("PUSH")); assertNull(sp.rdp("PUSH")); }