Example #1
0
    @Override
    public void run() {
      Random rnd = new Random();
      // a random update

      String randomUpdateValue = String.valueOf(rnd.nextInt(99999));

      testMap.put(this.key, randomUpdateValue);

      KeyImpl keyUpdate = new KeyImpl();
      keyUpdate.setKey(key);

      ValueImpl value = new ValueImpl();
      value.setValue(randomUpdateValue);

      ValueListImpl valueUpdateList = new ValueListImpl();
      valueUpdateList.getValueList().add(value);

      try {
        kvbis.update(keyUpdate, valueUpdateList);
        updatedValue = randomUpdateValue;
      } catch (IOException_Exception e) {
        e.printStackTrace();
        System.out.println("1");
      } catch (KeyNotFoundException_Exception e) {
        e.printStackTrace();
        System.out.println("2");
      } catch (ServiceNotInitializedException_Exception e) {
        e.printStackTrace();
        System.out.println("3");
      }
    }
Example #2
0
  @Test
  public void parallelRead() {
    Random rnd = new Random();
    int N = 10;

    // write N key values in hashmap and store
    for (int i = 0; i < N; i++) {
      String keyValue = String.valueOf(rnd.nextInt(999999));
      String resultValue = String.valueOf(rnd.nextInt(99999));

      KeyImpl key = new KeyImpl();
      key.setKey(keyValue);

      ValueImpl value = new ValueImpl();
      value.setValue(resultValue);

      ValueListImpl valueList = new ValueListImpl();
      valueList.getValueList().add(value);
      try {
        kvbis.insert(key, valueList);
        testMap.put(keyValue, resultValue);
      } catch (KeyAlreadyPresentException_Exception e) {
        // do nothing
      } catch (IOException_Exception e) {
        e.printStackTrace();
      } catch (ServiceNotInitializedException_Exception e) {
        e.printStackTrace();
      }
    }

    keys = new ArrayList<String>(testMap.keySet());
    String randomUpdateKey = keys.get(rnd.nextInt(keys.size()));

    Runnable updater = new UpdateThread(randomUpdateKey);
    Thread updateThread = new Thread(updater);
    updateThread.start();

    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    Runnable reader = new ReadThread(randomUpdateKey);
    Thread readThread = new Thread(reader);
    readThread.start();

    try {
      readThread.join();
      updateThread.join();
    } catch (InterruptedException e) {

    }

    // if one read failed fail test case
    assertEquals("Result", readValue, updatedValue);
  }
Example #3
0
    @Override
    public void run() {
      Random rnd = new Random();
      String actualValue = "";

      KeyImpl keyRead = new KeyImpl();
      keyRead.setKey(this.key);

      try {
        actualValue = kvbis.read(keyRead).getValueList().get(0).getValue().toString();
        readValue = actualValue;
      } catch (IOException_Exception e) {
        e.printStackTrace();
      } catch (KeyNotFoundException_Exception e) {
        e.printStackTrace();
      } catch (ServiceNotInitializedException_Exception e) {
        e.printStackTrace();
      }
    }