Example #1
0
  @Test
  public void testBatchTask() throws Exception {

    AtomicInteger counter = new AtomicInteger(0);

    BatchTask batch = new BatchTask(m_coordinator, null);

    batch.add(incr(counter));
    batch.add(incr(counter));
    batch.add(incr(counter));

    batch.schedule();

    batch.waitFor(3500, TimeUnit.MILLISECONDS);

    assertEquals(3, counter.get());
  }
Example #2
0
  @Test
  public void testLargeBatchInProgress() throws Exception {

    long count = 10;
    long loops = 1000;
    long total = count * loops;

    AtomicLong result = new AtomicLong(0);

    BatchTask task = new BatchTask(m_coordinator, null);

    task.add(scheduler(task, result, 1, count, loops - 1));

    task.schedule();

    task.waitFor();

    assertEquals(total * (total + 1) / 2, result.get());
  }
Example #3
0
  @Test
  public void testLargeBatch() throws Exception {

    long count = 500;

    AtomicLong result = new AtomicLong(0);

    BatchTask task = new BatchTask(m_coordinator, null);

    for (long i = 1; i <= count; i++) {
      task.add(addr(result, i));
    }

    task.schedule();

    task.waitFor();

    assertEquals(count * (count + 1) / 2, result.get());
  }
Example #4
0
  public boolean processTask(int taskId) {

    String s = (String) data_vec.elementAt(taskId);

    super.print("processing: " + s);

    try {

      Vector<String> w = getTokenStr(s, 9);
      String name = (String) w.elementAt(0);

      if (super.checkNoErrors(w, taskId)) {
        // ok
      } else {
        return false;
      }

      String edit = (String) w.elementAt(1);

      String attribute = (String) w.elementAt(2);

      String attributeName = (String) w.elementAt(3);

      String attributeValue = (String) w.elementAt(4);

      String newAttributeValue = (String) w.elementAt(5);

      owlModel.beginTransaction("BatchEdit. Processing " + s);

      // this should be false???
      boolean retval = false;
      if (edit.compareToIgnoreCase("new") == 0) {
        if (attribute.compareToIgnoreCase("property") == 0) {
          if (attributeName.compareToIgnoreCase(NCIEditTab.ALTLABEL) == 0) {
            OWLNamedClass hostClass = wrapper.getOWLNamedClass(name);
            retval =
                wrapper.addAnnotationProperty(
                    hostClass,
                    NCIEditTab.ALTLABEL,
                    owlModel.createRDFSLiteral(
                        attributeValue, owlModel.getSystemFrames().getXmlLiteralType()));
          } else {
            retval = wrapper.addAnnotationProperty(name, attributeName, attributeValue);
          }

        } else if (attribute.compareToIgnoreCase("parent") == 0) {
          OWLNamedClass hostClass = wrapper.getOWLNamedClass(name);
          OWLNamedClass targetClass = wrapper.getOWLNamedClass(attributeName);
          retval = wrapper.addDirectSuperclass(hostClass, targetClass);
        } else if (attribute.compareToIgnoreCase("association") == 0) {
          OWLNamedClass hostClass = wrapper.getOWLNamedClass(name);
          retval = wrapper.addObjectProperty(hostClass, attributeName, attributeValue);
        } else if (attribute.compareToIgnoreCase("role") == 0) {
          int pos = attributeValue.indexOf('|');
          String modifier = attributeValue.substring(0, pos);
          String value = attributeValue.substring(pos + 1);
          retval = wrapper.addRestriction(name, attributeName, value, modifier);
        }
      } else if (edit.compareToIgnoreCase("delete") == 0) {
        if (attribute.compareToIgnoreCase("property") == 0) {
          retval = wrapper.removeAnnotationProperty(name, attributeName, attributeValue);
        } else if (attribute.compareToIgnoreCase("parent") == 0) {
          OWLNamedClass hostClass = wrapper.getOWLNamedClass(name);
          OWLNamedClass targetClass = wrapper.getOWLNamedClass(attributeName);

          RDFSClass definition = hostClass.getDefinition();
          if (definition == null) {
            retval = wrapper.removeDirectSuperclass(hostClass, targetClass);
          } else {
            retval = wrapper.removeEquivalentDefinitionNew(hostClass, targetClass);
          }

        } else if (attribute.compareToIgnoreCase("association") == 0) {
          OWLNamedClass hostClass = wrapper.getOWLNamedClass(name);
          retval = wrapper.removeObjectProperty(hostClass, attributeName, attributeValue);
        } else if (attribute.compareToIgnoreCase("role") == 0) {
          int pos = attributeValue.indexOf('|');
          String modifier = attributeValue.substring(0, pos);
          String value = attributeValue.substring(pos + 1);
          retval = wrapper.removeRestriction(name, attributeName, value, modifier);
        }
      } else if (edit.compareToIgnoreCase("edit") == 0) {
        if (attribute.compareToIgnoreCase("property") == 0) {

          retval =
              wrapper.modifyAnnotationProperty(
                  name, attributeName, attributeValue, newAttributeValue);
          possiblySyncPreferredTerm(name, attributeName, newAttributeValue);

        } else if (attribute.compareToIgnoreCase("role") == 0) {
          int pos = attributeValue.indexOf('|');
          String modifier = attributeValue.substring(0, pos);
          String value = attributeValue.substring(pos + 1);

          pos = newAttributeValue.indexOf('|');
          String newmodifier = newAttributeValue.substring(0, pos);
          String newvalue = newAttributeValue.substring(pos + 1);

          retval =
              wrapper.modifyRestriction(
                  name, attributeName, value, modifier, newvalue, newmodifier);
        } else if (attribute.compareToIgnoreCase("association") == 0) {
          OWLNamedClass hostClass = wrapper.getOWLNamedClass(name);

          retval = wrapper.removeObjectProperty(hostClass, attributeName, attributeValue);
          retval = wrapper.addObjectProperty(hostClass, attributeName, newAttributeValue);
        }
      }

      // to be implemented
      /*
       * else if (edit.compareToIgnoreCase("delete-all") == 0) { }
       */

      if (retval) {
        tab.recordHistory(NCIEditTab.EVSHistoryAction.MODIFY, wrapper.getOWLNamedClass(name), "");
        super.print("\t Done.");
      } else {
        super.print("\t Failed.");
      }
      owlModel.commitTransaction();

    } catch (Exception ex) {

      owlModel.rollbackTransaction();
      print("Server Error occurred:");
      ex.printStackTrace();
      super.print(" Failed.");
      data_vec.remove(taskId);
      this.setMax(max - 1);
      return false;
    }

    return true;
  }