コード例 #1
0
  @Test
  public void testBasicLocalSync() throws Exception {
    waitForFullMesh(2000);

    ArrayList<IStoreClient<String, String>> clients =
        new ArrayList<IStoreClient<String, String>>(syncManagers.length);
    // write one value to each node's local interface
    for (int i = 0; i < syncManagers.length; i++) {
      IStoreClient<String, String> client =
          syncManagers[i].getStoreClient("local", String.class, String.class);
      clients.add(client);
      client.put("key" + i, "" + i);
    }

    // verify that we see all the values from each local group at all the
    // nodes of that local group
    for (int j = 0; j < clients.size(); j++) {
      IStoreClient<String, String> client = clients.get(j);
      for (int i = 0; i < syncManagers.length; i++) {
        if (i % 2 == j % 2) waitForValue(client, "key" + i, "" + i, 2000, "client" + j);
        else {
          Versioned<String> v = client.get("key" + i);
          if (v.getValue() != null) {
            fail("Node " + j + " reading key" + i + ": " + v.getValue());
          }
        }
      }
    }
  }
コード例 #2
0
  @Test
  public void testBasicOneNode() throws Exception {
    AbstractSyncManager sync = syncManagers[0];
    IStoreClient<Key, TBean> testClient = sync.getStoreClient("global", Key.class, TBean.class);
    Key k = new Key("com.bigswitch.bigsync.internal", "test");
    TBean tb = new TBean("hello", 42);
    TBean tb2 = new TBean("hello", 84);
    TBean tb3 = new TBean("hello", 126);

    assertNotNull(testClient.get(k));
    assertNull(testClient.get(k).getValue());

    testClient.put(k, tb);
    Versioned<TBean> result = testClient.get(k);
    assertEquals(result.getValue(), tb);

    result.setValue(tb2);
    testClient.put(k, result);

    try {
      result.setValue(tb3);
      testClient.put(k, result);
      fail("Should get ObsoleteVersionException");
    } catch (ObsoleteVersionException e) {
      // happy town
    }

    result = testClient.get(k);
    assertEquals(tb2, result.getValue());
  }
コード例 #3
0
  protected static <K, V> Versioned<V> waitForValue(
      IStoreClient<K, V> client, K key, V value, int maxTime, String clientName) throws Exception {
    Versioned<V> v = null;
    long then = System.currentTimeMillis();
    while (true) {
      v = client.get(key);
      if (value != null) {
        if (v.getValue() != null && v.getValue().equals(value)) break;
      } else {
        if (v.getValue() != null) break;
      }
      if (v.getValue() != null)
        logger.info(
            "{}: Value for key {} not yet right: " + "expected: {}; actual: {}",
            new Object[] {clientName, key, value, v.getValue()});
      else
        logger.info(
            "{}: Value for key {} is null: expected {}", new Object[] {clientName, key, value});

      Thread.sleep(100);
      assertTrue(then + maxTime > System.currentTimeMillis());
    }
    return v;
  }