@SuppressWarnings("unchecked") public synchronized V in (Object key) { Object obj; while ((obj = inp (key)) == null) { try { this.wait (); } catch (InterruptedException ignored) { } } return (V) obj; } @SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") public synchronized V in (Object key, long timeout) { Object obj; long now = System.currentTimeMillis(); long end = now + timeout; while ((obj = inp (key)) == null && (now = System.currentTimeMillis()) < end) { try { this.wait (end - now); } catch (InterruptedException ignored) { } } return (V) obj; }
public synchronized void put (K key, V value, long timeout) { while (inp (key) != null) ; // NOPMD out (key, value, timeout); } public synchronized void put (K key, V value) {
public synchronized void put (K key, V value) { while (inp (key) != null) ; // NOPMD out (key, value); } public void gc () throws DatabaseException {
public void testByteArray() throws Exception { String S = "The quick brown fox jumped over the lazy dog"; sp.out ("ByteArray", S.getBytes()); assertEquals (S, new String ((byte[]) sp.inp ("ByteArray"))); } public void testGC() throws Exception {
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")); } public void testExist() {
public void testTemplate () throws Exception { String key = "TemplateTest_Key"; sp.out (key, "Value 1"); sp.out (key, "Value 2"); sp.out (key, "Value 3"); String k2r = (String)sp.rdp (new MD5Template (key, "Value 2")); assertEquals (k2r, "Value 2"); String k2i = (String)sp.inp (new MD5Template (key, "Value 2")); assertEquals (k2i, "Value 2"); assertEquals ("Value 1", (String) sp.inp (key)); assertEquals ("Value 3", (String) sp.inp (key)); } public void testPush() {
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))); assertTrue (sp.rdp (k) == null); assertTrue (sp.rd (k, 100) == null); } public void testMultiKeyLoad() throws Exception {
public void testExistWithTimeout() { assertFalse ( "existAnyWithTimeout ([KA,KB])", sp.existAny (new String[] { "KA", "KB" }) ); assertFalse ( "existAnyWithTimeout ([KA,KB], delay)", sp.existAny (new String[] { "KA", "KB" }, 1000L) ); new Thread() { public void run() { ISOUtil.sleep (1000L); sp.out ("KA", Boolean.TRUE); } }.start(); long now = System.currentTimeMillis(); assertTrue ( "existAnyWithTimeout ([KA,KB], delay)", sp.existAny (new String[] { "KA", "KB" }, 2000L) ); long elapsed = System.currentTimeMillis() - now; assertTrue ("delay was > 1000", elapsed > 900L); assertNotNull ("Entry should not be null", sp.inp ("KA")); } public void testByteArray() throws Exception {
public void testPut () { sp.out ("PUT", "ONE"); sp.out ("PUT", "TWO"); sp.put ("PUT", "ZERO"); assertEquals ("ZERO", sp.rdp ("PUT")); assertEquals ("ZERO", sp.inp ("PUT")); assertNull (sp.rdp ("PUT")); } public void testPersistentContext() throws Exception {