Esempio n. 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");
      }
    }
Esempio n. 2
0
  public static void main(String[] args) {
    KeyValueBaseImplServiceService kvbiss = new KeyValueBaseImplServiceService();
    KeyValueBaseImplService kvbis = kvbiss.getKeyValueBaseImplServicePort();

    try {

      KeyImpl key = new KeyImpl();
      key.setKey("testKey");

      ValueImpl value = new ValueImpl();
      value.setValue("testValue");

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

      KeyImpl key2 = new KeyImpl();
      key.setKey("testKey2");

      ValueImpl value2 = new ValueImpl();
      value.setValue("testValue2");

      ValueListImpl valueList2 = new ValueListImpl();
      valueList.getValueList().add(value2);

      // kvbis.insert(key, valueList);
      // kvbis.insert(key2, valueList2);
      // kvbis.update(key, valueList2);
      // kvbis.delete(key2);

      System.out.println("Output: " + kvbis.read(key).getValueList().get(0).getValue());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 3
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);
  }
Esempio n. 4
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();
      }
    }