Ejemplo n.º 1
0
  /** Tests whether different stores are really independent. */
  public void testIndependentStores() throws StorageException {
    IStore store2 = storageSystem.openStore("other");

    store.put(KEY, VALUE);
    assertTrue(Arrays.equals(VALUE, store.get(KEY)));
    assertNull(store2.get(KEY));
  }
Ejemplo n.º 2
0
  /** Tests removal of elements. */
  public void testRemoveElement() throws StorageException {
    store.put(KEY, VALUE);
    assertTrue(Arrays.equals(VALUE, store.get(KEY)));

    store.remove(KEY);
    assertNull(store.get(KEY));
  }
Ejemplo n.º 3
0
  /** Tests scanning for multiple prefixes. */
  public void testScanPrefixMultiple() throws StorageException {
    List<String> keys =
        Arrays.asList(
            "/root/foo", "/root/bar", "/root/baz", "/some/other/file", "/a/different/file");
    for (String s : keys) {
      store.put(StringUtils.stringToBytes(s), new byte[] {});
    }

    // well-known prefix
    store.scan(Arrays.asList(StringUtils.stringToBytes("/roo")), callback);
    checkSubsetAndClear(3, keys, callback.keys);

    // overlapping prefix
    store.scan(
        Arrays.asList(StringUtils.stringToBytes("/roo"), StringUtils.stringToBytes("/root/f")),
        callback);
    checkSubsetAndClear(3, keys, callback.keys);

    // no prefixes
    store.scan(new ArrayList<byte[]>(), callback);
    checkSubsetAndClear(0, keys, callback.keys);

    // multiple
    store.scan(
        Arrays.asList(StringUtils.stringToBytes("/roo"), StringUtils.stringToBytes("/a/di")),
        callback);
    checkSubsetAndClear(4, keys, callback.keys);
  }
Ejemplo n.º 4
0
  /** Tests the corner case in prefix scanning interface. */
  public void testScanPrefixCornerCase() throws StorageException {
    byte[] prefix = {17, 18, 19, (byte) 0xff};
    store.put(prefix, prefix);

    CollectingCallBack callback = new CollectingCallBack();
    store.scan(prefix, callback);
    assertEquals(1, callback.keys.size());
  }
Ejemplo n.º 5
0
  /** Tests whether data is really lost during deletion of store. */
  public void testDeleteStore() throws StorageException {
    store.put(KEY, VALUE);
    assertTrue(Arrays.equals(VALUE, store.get(KEY)));

    storageSystem.removeStore(STORE);
    store = storageSystem.openStore(STORE);
    assertNull(store.get(KEY));
  }
Ejemplo n.º 6
0
  /** Test scanning for keys with begin and end. */
  public void testScanKeysBeginEnd() throws StorageException {
    store.put(new byte[] {1}, new byte[] {1});
    store.put(new byte[] {2}, new byte[] {2});
    store.put(new byte[] {3}, new byte[] {3});
    store.put(new byte[] {4}, new byte[] {1});

    store.scanKeys(new byte[] {2}, new byte[] {4}, callback);
    assertEquals(2, callback.keys.size());
  }
Ejemplo n.º 7
0
  /** Tests whether persistence between open/close works. */
  public void testPersistence() throws StorageException {
    store.put(KEY, VALUE);
    assertTrue(Arrays.equals(VALUE, store.get(KEY)));

    storageSystem.close();
    storageSystem = openStorage(baseDir);

    store = storageSystem.openStore(STORE);
    assertTrue(Arrays.equals(VALUE, store.get(KEY)));
  }
Ejemplo n.º 8
0
  /** Tests the very basic set/get interface. */
  public void testSetGet() throws StorageException {
    // key does not exist in empty store
    assertNull(store.get(KEY));

    // put affects result of get
    store.put(KEY, VALUE);
    assertTrue(Arrays.equals(VALUE, store.get(KEY)));

    // other keys do not affect result of get
    store.put(new byte[] {7, 8, 9}, new byte[] {17, 18, 19});
    assertTrue(Arrays.equals(VALUE, store.get(KEY)));
  }
Ejemplo n.º 9
0
  /** Test for multi-get and set. */
  public void testSetGetMultiple() throws StorageException {
    PairList<byte[], byte[]> entries = new PairList<byte[], byte[]>();
    entries.add(new byte[] {1}, new byte[] {1});
    entries.add(new byte[] {2}, new byte[] {2});
    store.put(entries);
    List<byte[]> values = store.get(Arrays.asList(new byte[] {1}, new byte[] {3}, new byte[] {2}));
    assertEquals(3, values.size());
    assertTrue(Arrays.equals(new byte[] {1}, values.get(0)));
    assertNull(values.get(1));
    assertTrue(Arrays.equals(new byte[] {2}, values.get(2)));

    store.remove(entries.extractFirstList());
    store.scan(new byte[] {}, callback);
    assertEquals(0, callback.keys.size());
  }
Ejemplo n.º 10
0
  /** Tests the prefix scanning interface. */
  public void testScanPrefix() throws StorageException {
    List<String> keys = Arrays.asList("/root/foo", "/root/bar", "/root/baz", "/some/other/file");
    for (String s : keys) {
      store.put(StringUtils.stringToBytes(s), new byte[] {});
    }

    // well-known prefix
    store.scan(StringUtils.stringToBytes("/roo"), callback);
    checkSubsetAndClear(3, keys, callback.keys);

    // invalid prefix
    store.scan(StringUtils.stringToBytes("inv"), callback);
    checkSubsetAndClear(0, keys, callback.keys);

    // empty prefix
    store.scan(new byte[] {}, callback);
    checkSubsetAndClear(keys.size(), keys, callback.keys);
  }
Ejemplo n.º 11
0
  /** Tests the range scanning interface. */
  public void testScanRange() throws StorageException {
    // space makes first key appear before others
    List<String> keys =
        Arrays.asList(StringUtils.SPACE + "first", "aab", "aac", "abc", "aaa", "aaaa");
    for (String s : keys) {
      store.put(StringUtils.stringToBytes(s), new byte[] {});
    }

    store.scan(StringUtils.stringToBytes("aaa"), StringUtils.stringToBytes("aaa"), callback);
    assertEquals(0, callback.keys.size());

    callback.keys.clear();
    store.scan(StringUtils.stringToBytes("aaa"), StringUtils.stringToBytes("aaab"), callback);
    assertEquals(
        new HashSet<String>(Arrays.asList("aaa", "aaaa")), new HashSet<String>(callback.keys));

    callback.keys.clear();
    store.scan(StringUtils.stringToBytes("aabq"), null, callback);
    assertEquals(
        new HashSet<String>(Arrays.asList("aac", "abc")), new HashSet<String>(callback.keys));
  }
Ejemplo n.º 12
0
 public void execute(Runnable runnable) {
   if (store instanceof XSSCookieStore && !store.isReady()) {
     /**
      * @j2sNative window.xssCookieReadyCallback = (function (r1, r2) { return function () {
      *     net.sf.j2s.store.XSSCookieStore.initialized = true; if (r1 != null) { try { r1.run ();
      *     } catch (e) { } } r2.run (); }; }) (window.xssCookieReadyCallback, runnable);
      *     window.setTimeout (function () { if (!net.sf.j2s.store.XSSCookieStore.initialized &&
      *     window.xssCookieReadyCallback != null) { window.xssCookieReadyCallback (); } }, 10000);
      */
     {
     }
     return;
   }
   runnable.run();
 }
Ejemplo n.º 13
0
 public void add(IStore store) {
   this.registry.put(store.getClass(), store);
   this.dispatch(new AppEvent(Events.Added, new Object[] {store}));
 }
Ejemplo n.º 14
0
 public boolean isReady() {
   return store.isReady();
 }
Ejemplo n.º 15
0
 public String getProperty(String name) {
   return store.getProperty(name);
 }
Ejemplo n.º 16
0
 public void setProperty(String name, String value) {
   store.setProperty(name, value);
 }
Ejemplo n.º 17
0
 /** Test scanning for keys with prefix. */
 public void testScanKeysPrefix() throws StorageException {
   store.put(new byte[] {1}, new byte[] {1});
   store.scanKeys(new byte[] {1}, callback);
   assertEquals(1, callback.keys.size());
 }