Package nexj.core.runtime

Examples of nexj.core.runtime.InstanceList


      Instance primary = (Instance)primaryClass.invoke("new");
      Instance primary2 = (Instance)primaryClass.invoke("new");
      Instance primary3 = (Instance)primaryClass.invoke("new");
      Instance scheduler = (Instance)schedulerClass.getValue("instance");
      Instance throttleCounterBatchJob = (Instance)throttleCounterBatchJobClass.getValue("instance");
      InstanceList workflowList, assignmentList;
      Instance workflow, assignment;
      List invocationList;

      // Initialization
      primary.setValue("trace", null);
      primary.setValue("throwOuterEx", Boolean.FALSE);
      primary.setValue("throwUncaughtEx", Boolean.FALSE);
      primary2.setValue("trace", null);
      primary2.setValue("throwOuterEx", Boolean.FALSE);
      primary2.setValue("throwUncaughtEx", Boolean.FALSE);
      primary3.setValue("trace", null);
      primary3.setValue("throwOuterEx", Boolean.FALSE);
      primary3.setValue("throwUncaughtEx", Boolean.FALSE);


      /*
       * Test: 3 jobs:
       * Job 1: started at 0 seconds, runs immediately (in window)
       * Job 2: started at 8 seconds, runs immediately (in window)
       * Job 3: started at 9 seconds, doesn't run (throttle exceeded)
       *
       * @ 60 seconds: Timer tick, job counter reset, job 3 resumed.
       */
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.ZERO_INTEGER));
      ((List)schedulerClass.getValue("asyncInvokeList")).clear();
      primary.setValue("queueName", "SemaphoreThrottled");
      primary2.setValue("queueName", "SemaphoreThrottled");
      primary3.setValue("queueName", "SemaphoreThrottled");
      primary.setValue("trace", null);
      primary2.setValue("trace", null);
      primary3.setValue("trace", null);
      primary.invoke("goSemaphore");

      invocationList = (List)schedulerClass.getValue("asyncInvokeList");
      assertEquals(1, invocationList.size());

      // Job 1: RUNNING
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assignmentList = (InstanceList)workflow.getValue("assignments");
      assertEquals(1, assignmentList.size());
      assignment = assignmentList.getInstance(0);
      assertEquals(Primitive.ONE_INTEGER, assignment.getValue("status"));
      assertEquals(assignment.getOID(), invocationList.get(0));

      // Simulate run/finish of Job 1
      assignment.invoke("schedulerRun");
      assertEquals(Instance.DELETED, assignment.getState());
      assertEquals(Instance.DELETED, workflow.getState());
      assertEquals("BEFORE;ASSIGNMENT_CREATE;EXECUTE_SEMAPHORE;END_SEMAPHORE;ASSIGNMENT_DELETE;AFTER;", primary.getValue("trace"));
      commit();


      // @ 8 seconds
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(8000)));
      primary2.invoke("goSemaphore");

      // Job 2: RUNNING
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary2});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assignmentList = (InstanceList)workflow.getValue("assignments");
      assertEquals(1, assignmentList.size());
      assignment = assignmentList.getInstance(0);
      assertEquals(Primitive.ONE_INTEGER, assignment.getValue("status"));
      assertEquals(2, invocationList.size());
      assertEquals(assignment.getOID(), invocationList.get(1));

      // Simulate run/finish of Job 2
      assignment.invoke("schedulerRun");
      assertEquals(Instance.DELETED, assignment.getState());
      assertEquals(Instance.DELETED, workflow.getState());
      assertEquals("BEFORE;ASSIGNMENT_CREATE;EXECUTE_SEMAPHORE;END_SEMAPHORE;ASSIGNMENT_DELETE;AFTER;", primary2.getValue("trace"));
      commit();

      // @ 9 seconds
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(9000)));
      primary3.invoke("goSemaphore");

      // Job 3: NOT RUNNING
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary3});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assignmentList = (InstanceList)workflow.getValue("assignments");
      assertEquals(1, assignmentList.size());
      assignment = assignmentList.getInstance(0);
      assertEquals(Primitive.ZERO_INTEGER, assignment.getValue("status"));
      assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary3.getValue("trace"));
      assertEquals(2, invocationList.size());


      // @ 60 seconds
      m_context.setSecure(false);
      throttleCounterBatchJob.invoke("run");
      m_context.setSecure(true);
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(60000)));
      scheduler.invoke("schedule");
      assertEquals(3, invocationList.size());
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary3});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assignmentList = (InstanceList)workflow.getValue("assignments");
      assertEquals(1, assignmentList.size());
      assignment = assignmentList.getInstance(0);
      assertEquals(Primitive.ONE_INTEGER, assignment.getValue("status"));
      assertEquals(assignment.getOID(), invocationList.get(2));
View Full Code Here


   {
      Metaclass workflowClass = getMetadata().getMetaclass(Metadata.WORKFLOW_CLASS_NAME);
      Metaclass primaryClass = getMetadata().getMetaclass("WorkflowTrace");
      Metaclass schedulerClass = getMetadata().getMetaclass("TestSysWorkflowSchedulerBatchJob");
      Instance primary = (Instance)primaryClass.invoke("new");
      InstanceList workflowList, assignmentList, timerList;
      Instance workflow, assignment, timeoutTimer;
      List invocationList;

      // Initialization
      primary.setValue("trace", null);
      primary.setValue("throwOuterEx", Boolean.FALSE);
      primary.setValue("throwUncaughtEx", Boolean.FALSE);

      /*
       * Test: One job, inside time window.
       */
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(1000)));
      primary.setValue("trace", null);
      primary.setValue("queueName", "Semaphore");
      timerList = getNonInitialTimers();
      assertEquals(0, timerList.size());
      primary.invoke("goProcessEvent");
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assignmentList = (InstanceList)workflow.getValue("assignments");
      assertEquals(1, assignmentList.size());
      assignment = assignmentList.getInstance(0);
      assertEquals(Boolean.TRUE, assignment.getValue("semaphore"));
      assertEquals(Primitive.ONE_INTEGER, assignment.getValue("status"));
      invocationList = (List)schedulerClass.getValue("asyncInvokeList");
      assertEquals(1, invocationList.size());
      assertEquals(assignment.getOID(), invocationList.get(0));
      assertEquals("BEGIN;", primary.getValue("trace"));
      timerList = getNonInitialTimers();
      assertEquals(0, timerList.size());


      // Simulate run
      assignment.invoke("schedulerRun");
      assertEquals(Instance.DELETED, assignment.getState());
      assertEquals(Instance.DELETED, workflow.getState());
      assertEquals("BEGIN;PROCESS_EVENT;PROCESS_EVENT_DONE;END;", primary.getValue("trace"));
      timerList = getNonInitialTimers();
      assertEquals(0, timerList.size());
      commit();


      /*
       * Test 2: One job, outside time window, canceled by class event.
       */
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(30000*3)));
      ((List)schedulerClass.getValue("asyncInvokeList")).clear();
      primary.setValue("trace", null);
      primary.setValue("queueName", "Semaphore");
      timerList = getNonInitialTimers();
      assertEquals(0, timerList.size());
      primary.invoke("goProcessEvent");
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assignmentList = (InstanceList)workflow.getValue("assignments");
      assertEquals(1, assignmentList.size());
      assignment = assignmentList.getInstance(0);
      assertEquals(Boolean.TRUE, assignment.getValue("semaphore"));
      assertEquals(Primitive.ZERO_INTEGER, assignment.getValue("status"));
      invocationList = (List)schedulerClass.getValue("asyncInvokeList");
      assertEquals(0, invocationList.size());
      assertEquals("BEGIN;", primary.getValue("trace"));

      // Scheduler runs
      commit();
      timerList = getNonInitialTimers();
      assertEquals(2, timerList.size())// Scheduler timer and the TimerEvent timer
      assertEquals(Instance.CLEAN, assignment.getState());
      assertEquals(Instance.CLEAN, workflow.getState());
      assertEquals("BEGIN;", primary.getValue("trace"));

      // Cancel event
      primary.invoke("resumeProcessEvent");
      assertEquals(Instance.DELETED, assignment.getState());
      assertEquals(Instance.DELETED, workflow.getState());
      assertEquals("BEGIN;CLASS_EVENT;END;", primary.getValue("trace"));
      timerList = getNonInitialTimers();
      assertEquals(1, timerList.size())// The scheduler timer remains
      timerList.getInstance(0).delete();
      commit();


      /*
       * Test 3: One job, outside time window, times out by Timer Event.
       */
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(30000*1)));
      ((List)schedulerClass.getValue("asyncInvokeList")).clear();
      primary.setValue("trace", null);
      primary.setValue("queueName", "Semaphore");
      timerList = getNonInitialTimers();
      assertEquals(0, timerList.size());
      primary.invoke("goProcessEvent");
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assignmentList = (InstanceList)workflow.getValue("assignments");
      assertEquals(1, assignmentList.size());
      assignment = assignmentList.getInstance(0);
      assertEquals(Boolean.TRUE, assignment.getValue("semaphore"));
      assertEquals(Primitive.ZERO_INTEGER, assignment.getValue("status"));
View Full Code Here

      commit();
   }

   protected Instance getTimeoutTimer(Instance workflow) throws Exception
   {
      InstanceList timerList = getNonInitialTimers();
      int i = 0;

      while (i < timerList.size())
      {
         Instance timer = timerList.getInstance(i);

         if (timer.getValue("workflow") == workflow)
         {
            return timer;
         }
View Full Code Here

   }

   protected InstanceList getNonInitialTimers() throws Exception
   {
      Metaclass timerClass = getMetadata().getMetaclass("SysTimer");
      InstanceList timerList = Query.createRead(timerClass, null, Boolean.TRUE, null, -1, 0, false, Query.SEC_NONE, m_context).read();
      int i = 0;

      while (i < timerList.size())
      {
         Instance timer = timerList.getInstance(i);
         OID timerOID = timer.getOID();

         assertEquals(1, timerOID.getCount());

         if (((Binary)timerOID.getValue(0)).toString().equals("00000000000000000000000000000001"))
         {
            timerList.remove(i);
         }
         else
         {
            i++;
         }
View Full Code Here

      Metaclass serviceClass = getMetadata().getMetaclass(Metadata.SERVICE_CLASS_NAME);
      Metaclass schedulerClass = getMetadata().getMetaclass("TestSysWorkflowSchedulerBatchJob");
      TransferObject tobj = new TransferObject();
      TransferObject result;
      Instance instance, assignment;
      InstanceList assignmentList;

      // Set scheduler time outside of the queue time window
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(15000)));


      // Test: no exception
      tobj.setValue("trace", "");
      tobj.setValue("throwOuterEx", Boolean.FALSE);
      tobj.setValue("throwUncaughtEx", Boolean.FALSE);
      instance = (Instance)serviceClass.invoke("invoke", new Object[]{"Semaphore", tobj, null});
      assertEquals(Boolean.FALSE, instance.invoke("done"));
      assertEquals("BEFORE;", tobj.getValue("trace"));
      assignmentList = (InstanceList)instance.getValue("assignments");
      assertEquals(1, assignmentList.size());
      assignment = assignmentList.getInstance(0);
      assertEquals(Boolean.TRUE, assignment.getValue("semaphore"));
      assertEquals(Primitive.ZERO_INTEGER, assignment.getValue("status"));
      commit();
      assignment.invoke("schedulerRun");
      assertEquals(Boolean.TRUE, instance.invoke("done"));
      assertEquals(Instance.DELETED, assignment.getState());
      result = (TransferObject)instance.invoke("result");
      assertEquals("BEFORE;EXECUTE_SEMAPHORE;END_SEMAPHORE;AFTER;", result.getValue("trace"));
      instance.delete();
      commit();


      // Test: caught exception
      tobj.setValue("trace", "");
      tobj.setValue("throwOuterEx", Boolean.TRUE);
      tobj.setValue("throwUncaughtEx", Boolean.FALSE);
      instance = (Instance)serviceClass.invoke("invoke", new Object[]{"Semaphore", tobj, null});
      assertEquals(Boolean.FALSE, instance.invoke("done"));
      assertEquals("BEFORE;", tobj.getValue("trace"));
      assignmentList = (InstanceList)instance.getValue("assignments");
      assertEquals(1, assignmentList.size());
      assignment = assignmentList.getInstance(0);
      assertEquals(Boolean.TRUE, assignment.getValue("semaphore"));
      assertEquals(Primitive.ZERO_INTEGER, assignment.getValue("status"));
      commit();
      assignment.invoke("schedulerRun");
      assertEquals(Boolean.TRUE, instance.invoke("done"));
      assertEquals(Instance.DELETED, assignment.getState());
      assertEquals(Primitive.createInteger(2), assignment.getValue("status"));
      result = (TransferObject)instance.invoke("result");
      assertEquals("BEFORE;EXECUTE_SEMAPHORE;CAUGHT_OUTER;", result.getValue("trace"));
      instance.delete();
      commit();


      // Test: uncaught exception
      tobj.setValue("trace", "");
      tobj.setValue("throwOuterEx", Boolean.FALSE);
      tobj.setValue("throwUncaughtEx", Boolean.TRUE);
      instance = (Instance)serviceClass.invoke("invoke", new Object[]{"Semaphore", tobj, null});
      assertEquals(Boolean.FALSE, instance.invoke("done"));
      assertEquals("BEFORE;", tobj.getValue("trace"));
      assignmentList = (InstanceList)instance.getValue("assignments");
      assertEquals(1, assignmentList.size());
      assignment = assignmentList.getInstance(0);
      assertEquals(Boolean.TRUE, assignment.getValue("semaphore"));
      assertEquals(Primitive.ZERO_INTEGER, assignment.getValue("status"));
      commit();

      try
View Full Code Here

    * during loop execution.
    */
   public void testWorkflowLoop()
   {
      Metaclass workflowClass = getMetadata().getMetaclass(Metadata.WORKFLOW_CLASS_NAME);
      InstanceList workflowList;
      Instance contact, workflow;
      Query query = Query.createRead(getMetadata().getMetaclass("Contact"),
         parse("((addresses country state city))"),
         parse("(and (= lastName \"Test\") (= firstName \"Joe\"))"),
         null,
         -1, 0, false, Query.SEC_NONE, m_context);
      InstanceList resultList = query.read();

      assertEquals(1, resultList.size());
      contact = resultList.getInstance(0);

      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{contact});
      assertEquals(0, workflowList.size());

      contact.invoke("start");
      commit();
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{contact});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assertEquals(1, ((List)workflow.getValue("assignments")).size());

      contact.invoke("process");
      commit();
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{contact});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assertEquals(1, ((List)workflow.getValue("assignments")).size());

      contact.invoke("break");
      commit();
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{contact});
      assertEquals(0, workflowList.size());

      InstanceList addressList = (InstanceList)contact.getValue("addresses");

      addressList.sort(new Comparator()
      {
         public int compare(Object left, Object right)
         {
            return ((Comparable)((Instance)left).getValue("city")).compareTo(((Instance)right).getValue("city"));
         }
      });

      assertEquals(2, addressList.size());
      assertEquals("Hong Kong", addressList.getInstance(0).getValue("city"));
      assertEquals("Richmond Hill", addressList.getInstance(1).getValue("city"));
   }
View Full Code Here

      Object where = parse("(and (like? firstName \"V*\") (= lastName \"Iordanov\") (= entityType 0n))");
      Pair orderBy = (Pair)parse("((firstName . #t)(lastName . #t)((@) . #t))");

      Query query = Query.createRead(contact, attributes, where, orderBy, 10, 0, false, Query.SEC_NONE, m_context);

      InstanceList list = query.read();
     
      for (int i = 0; i < list.size(); ++i)
      {
         s_logger.dump("fullName[" + i + "] = \"" + list.getInstance(i).getValue("fullName") + "\"");
      }
     
      Metaclass address = Repository.getMetadata().getMetaclass("XJAddress");
      attributes = (Pair)parse("(country city)");
      where = new Pair(Symbol.EQ, new Pair (parse("(@@ XJContact addresses)"), new Pair(new OID(new Object[]{"12345678901234567890123456789012"}))));

      query = Query.createRead(address, attributes, where, null, 10, 0, false, Query.SEC_NONE, m_context);
      query.read();
     
      Metaclass xjobj = Repository.getMetadata().getMetaclass("XJJObj");
      attributes = (Pair)parse("(mimeType mimeData)");
      where = new Pair(Symbol.EQ, new Pair (parse("(@@ XJContact image)"), new Pair(new OID(new Object[]{"78B14B58F66611CEBB8500AA0020A75A"}))));
      query = Query.createRead(xjobj, attributes, where, null, 1, 0, false, Query.SEC_NONE, m_context);
      list = query.read();
     
      if (list.size() == 1)
      {
         s_logger.debug("mime = " + list.getInstance(0).getValue("mimeType"));
        
         try
         {
               FileOutputStream fos = new FileOutputStream("c:/tmp/pic.bin");
               fos.write(((Binary)list.getInstance(0).getValue("mimeData")).getData());
               fos.close();
         }
         catch (Exception e)
         {
            s_logger.error("Exception", e);
View Full Code Here

TOP

Related Classes of nexj.core.runtime.InstanceList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.