Package nexj.core.runtime

Examples of nexj.core.runtime.InstanceList


    * in a single query.
    */
   public void testReadMultipleAssocs()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      InstanceList list, col;
      Instance inst, assoc1, assoc2, assoc21, assoc3, assoc31;

      list = (InstanceList)Query.createRead(animalClass,
         parse("(commonName (licenses name) (fondOf commonName (fondOf commonName)) (pen name) (chaserOf commonName (pen name)))"),
         parse("(= (@ commonName) \"Dog\")"),
         null, -1, 0, false, Query.SEC_NODE, m_context).read();

      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));

      assoc1 = (Instance)inst.getValue("pen");
      assertEquals("Dog pen", assoc1.getValue("name"));

View Full Code Here


    */
   public void testReadManyToOneHeterogeneousAssocWithNonLazyCollectionsOnAssociatedInstances()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Instance inst, assocInst;
      InstanceList list;
      int nStartCallCount, nEndCallCount;

      list = Query.createRead(animalClass, parse("(commonName limbCount (pen name animals))"),
         null, null, -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(4, list.size());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      assocInst = (Instance)inst.getValue("pen");
      assertNotNull(assocInst);
      assertEquals("Dog pen", assocInst.getValue("name"));
      nStartCallCount = ((Integer)animalClass.getValue("penAttrReadCount")).intValue();
      assertEquals(2, ((InstanceList)assocInst.getValue("animals")).size());
      nEndCallCount = ((Integer)animalClass.getValue("penAttrReadCount")).intValue();
      assertEquals(nStartCallCount, nEndCallCount)// Loaded during read
      assertSame(inst, ((InstanceList)assocInst.getValue("animals")).getInstance(0));

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      assocInst = (Instance)inst.getValue("pen");
      assertNotNull(assocInst);
      assertEquals("Cat pen", assocInst.getValue("name"));
      nStartCallCount = ((Integer)animalClass.getValue("penAttrReadCount")).intValue();
      assertEquals(1, ((InstanceList)assocInst.getValue("animals")).size());
      nEndCallCount = ((Integer)animalClass.getValue("penAttrReadCount")).intValue();
      assertEquals(nStartCallCount, nEndCallCount)// Loaded during read
      assertSame(inst, ((InstanceList)assocInst.getValue("animals")).getInstance(0));

      inst = list.getInstance(2);
      assertEquals("Spider", inst.getValue("commonName"));
      assocInst = (Instance)inst.getValue("pen");
      assertNotNull(assocInst);
      assertEquals("Dog pen", assocInst.getValue("name"));
      nStartCallCount = ((Integer)animalClass.getValue("penAttrReadCount")).intValue();
View Full Code Here

    * Tests reading an instance-cached class directly.
    */
   public void testReadCached()
   {
      Metaclass clazz = m_metadata.getMetaclass("CachedVirtual");
      InstanceList list;
      Instance inst;

      m_context.getGlobalCache().clear();
      clazz.setValue("readCount", Primitive.ZERO_INTEGER);

      // This query fills the cache
      list = Query.createRead(clazz, parse("(x (assoc x))"), parseEval("`(= (@) ,(oid 1))"), null, -1, 0, false, Query.SEC_ALL, m_context).read();

      assertEquals(Primitive.ONE_INTEGER, clazz.getValue("readCount")); // verify that the read was executed
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("101", inst.getValue("x"));
      assertNull(inst.getValue("assoc"));
      assertEquals(Primitive.ONE_INTEGER, clazz.getValue("readCount")); // no lazy

      m_context.removeInstance(inst);
      inst = null;
      list = null;

      // This query should hit the cache
      list = Query.createRead(clazz, parse("(x (assoc x))"), parseEval("`(= (@) ,(oid 1))"), null, -1, 0, false, Query.SEC_ALL, m_context).read();

      assertEquals(Primitive.ONE_INTEGER, clazz.getValue("readCount")); // cache hit
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("101", inst.getValue("x"));
      assertNull(inst.getValue("assoc"));
      assertEquals(Primitive.ONE_INTEGER, clazz.getValue("readCount")); // no lazy

      m_context.removeInstance(inst);
      inst = null;
      list = null;

      // Clear caches
      m_context.getUnitOfWork().rollback();
      m_context.getGlobalCache().clear();

      // This query should miss the cache
      list = Query.createRead(clazz, parse("(x (assoc x))"), parseEval("`(= (@) ,(oid 1))"), null, -1, 0, false, Query.SEC_ALL, m_context).read();

      assertEquals(Primitive.createInteger(2), clazz.getValue("readCount")); // cache miss
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("101", inst.getValue("x"));
      assertNull(inst.getValue("assoc"));
      assertEquals(Primitive.createInteger(2), clazz.getValue("readCount")); // no lazy
   }
View Full Code Here

    * Tests reading an instance-cached class through an association.
    */
   public void testReadCachedAssoc()
   {
      Metaclass clazz = m_metadata.getMetaclass("CachedVirtual");
      InstanceList list;
      Instance inst;
      Instance assoc;

      m_context.getGlobalCache().clear();
      clazz.setValue("readCount", Primitive.ZERO_INTEGER);

      // This query fills the cache with key (CachedVirtual . OID:1:I1:3)
      list = Query.createRead(clazz, parse("(x (assoc x))"), parseEval("`(= (@) ,(oid 3))"), null, -1, 0, false, Query.SEC_ALL, m_context).read();

      assertEquals(Primitive.createInteger(1), clazz.getValue("readCount")); // verify that the read was executed
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("303", inst.getValue("x"));
      assertNull(inst.getValue("assoc"));
      assertEquals(Primitive.createInteger(1), clazz.getValue("readCount")); // no lazy

      m_context.removeInstance(inst);
      inst = null;
      list = null;

      // The association query does not hit the cache because key is (:class CachedVirtual "(= (@ <"<OID_TYPE>">) #<OID:1:I1:3>)")
      list = Query.createRead(clazz, parse("(x (assoc x))"), parseEval("`(= (@) ,(oid 2))"), null, -1, 0, false, Query.SEC_ALL, m_context).read();

      assertEquals(Primitive.createInteger(3), clazz.getValue("readCount")); // reads both again
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("202", inst.getValue("x"));
      assoc = (Instance)inst.getValue("assoc");
      assertEquals("303", assoc.getValue("x"));
      assertEquals(Primitive.createInteger(3), clazz.getValue("readCount")); // no lazy

      m_context.removeInstance(inst);
      m_context.removeInstance(assoc);
      assoc = inst = null;
      list = null;

      // The association query does hit the cache because the where clause cache key is now known (from the previous read)
      list = Query.createRead(clazz, parse("(x (assoc x))"), parseEval("`(= (@) ,(oid 4))"), null, -1, 0, false, Query.SEC_ALL, m_context).read();

      assertEquals(Primitive.createInteger(4), clazz.getValue("readCount")); // reads (oid 4), but (oid 3) is taken from cache
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("404", inst.getValue("x"));
      assoc = (Instance)inst.getValue("assoc");
      assertEquals("303", assoc.getValue("x"));
      assertEquals(Primitive.createInteger(4), clazz.getValue("readCount")); // no lazy

      m_context.removeInstance(inst);
      m_context.removeInstance(assoc);
      assoc = inst = null;
      list = null;

      // Clear caches
      m_context.getUnitOfWork().rollback();
      m_context.getGlobalCache().clear();

      // This query should miss the cache
      list = Query.createRead(clazz, parse("(x (assoc x))"), parseEval("`(= (@) ,(oid 2))"), null, -1, 0, false, Query.SEC_ALL, m_context).read();

      assertEquals(Primitive.createInteger(6), clazz.getValue("readCount")); // cache miss
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("202", inst.getValue("x"));
      assoc = (Instance)inst.getValue("assoc");
      assertEquals("303", assoc.getValue("x"));
      assertEquals(Primitive.createInteger(6), clazz.getValue("readCount")); // no lazy
   }
View Full Code Here

   /**
    *  Bug #25488: formatting complex object messages can cause ArrayIndexOutOfBoundsException.
    */
   public void testSubclassInMessage() throws Exception
   {
      InstanceList instances = Query.createRead(getMetadata().getMetaclass("Contact"), null, null, null, -1, 0, false, Query.SEC_NONE, m_context).read();
      Instance contact = null;
      Instance doctor = null;

      for (Iterator itr = instances.iterator(); itr.hasNext(); )
      {
         Instance instance = (Instance)itr.next();
        
         if (instance.getMetaclass().getName().equals("Contact"))
         {
            contact = instance;
         }
        
         if (instance.getMetaclass().getName().equals("Doctor"))
         {
            doctor = instance;
         }
      }

      Metaclass supportGroupMetaclass = getMetadata().getMetaclass("SupportGroup");
      Instance group = new Instance(supportGroupMetaclass, m_context);
      InstanceList participants = new InstanceArrayList(2);
     
      group.setNew();
      group.setValue("name", "A group");
      group.setValue("participants", participants);
      participants.add(doctor);
      doctor.setValue("licenseNumber", "Lic 01");
      commit();
     
      group = Query.createRead(supportGroupMetaclass, null, null, null, -1, 0, false, Query.SEC_NONE, m_context).read().getInstance(0);
     
View Full Code Here

   /**
    *  Bug #25494: ObjectMessageFormatter reads the entire graph in one select. This can cause StackOverflowError.
    */
   public void testCircularMessage() throws Exception
   {
      InstanceList instances = Query.createRead(getMetadata().getMetaclass("Account"),
         parse("(funds (contact lastName (@@ Doctor licenseNumber)))"),
         null, null, -1, 0, false, Query.SEC_NONE, m_context).read();
     
      for (Iterator itr = instances.iterator(); itr.hasNext(); )
      {
         Instance account = (Instance)itr.next();
         TransferObject accountTobj = m_parser.parse(new ObjectInput(account), getMessage("Object_AccountRecursive"));
         TransferObject contactTobj = (TransferObject)accountTobj.getValue("contact");

View Full Code Here

    * exception is thrown on a different branch of the Fork/Join.
    */
   public void testWorkflowTryFinallyInFork() throws Exception
   {
      Metaclass assignmentClass = getMetadata().getMetaclass("SysWorkflowAssignment");
      InstanceList assignmentList;
      Metaclass primaryClass = getMetadata().getMetaclass("WorkflowTrace");
      Instance primary = (Instance)primaryClass.invoke("new");

      // Test 1: No exception
      primary.setValue("trace", null);
      primary.setValue("throwUncaughtEx", Boolean.FALSE);
      primary.setValue("throwInnerEx", Boolean.FALSE);
      primary.invoke("goForkTry");
      assignmentList = Query.createRead(assignmentClass, null, Boolean.TRUE, null, -1, 0, false, Query.SEC_NONE, m_context).read();
      assertEquals(1, assignmentList.size());
      primary.invoke("resumeForkTry");
      commit();
      assertTrue("scrStart;scrLeft1;scrLeft2;scrLeft3;scrRight1;scrLeft4;scrRight2;scrRight3;scrInnerFinally;scrOuterFinally;scrFinish;".equals(primary.getValue("trace")) ||
                 "scrStart;scrLeft1;scrLeft2;scrLeft3;scrLeft4;scrRight1;scrRight2;scrRight3;scrInnerFinally;scrOuterFinally;scrFinish;".equals(primary.getValue("trace")));
      assignmentList = Query.createRead(assignmentClass, null, Boolean.TRUE, null, -1, 0, false, Query.SEC_NONE, m_context).read();
      assertEquals(0, assignmentList.size());


      // Test 2: Caught Exception
      primary.setValue("trace", null);
      primary.setValue("throwUncaughtEx", Boolean.FALSE);
      primary.setValue("throwInnerEx", Boolean.TRUE);
      primary.invoke("goForkTry");
      commit();
     
      // If DEBUG log mode, then State gets sorted so that left branch of Fork/Join is preferred. This prevents
      // entry to right branch's Try block. Thus the right hand (inner) Finally may not be executed.
      assertTrue("scrStart;scrLeft1;scrLeft2;scrLeft3;scrRight1;scrLeft4;scrInnerFinally;scrCatch;scrOuterFinally;scrFinish;".equals(primary.getValue("trace")) ||
                 "scrStart;scrLeft1;scrLeft2;scrLeft3;scrLeft4;scrCatch;scrOuterFinally;scrFinish;".equals(primary.getValue("trace")));
      assignmentList = Query.createRead(assignmentClass, null, Boolean.TRUE, null, -1, 0, false, Query.SEC_NONE, m_context).read();
      assertEquals(0, assignmentList.size());

      // Test 3: Uncaught Exception
      primary.setValue("trace", null);
      primary.setValue("throwUncaughtEx", Boolean.TRUE);
      primary.setValue("throwInnerEx", Boolean.FALSE);

      try
      {
         primary.invoke("goForkTry");
         fail("Exception not thrown");
      }
      catch (ScriptingException ex)
      {
        
          // If DEBUG log mode, then State gets sorted so that left branch of Fork/Join is preferred. This prevents
          // entry to right branch's Try block. Thus the right hand (inner) Finally may not be executed.
         assertTrue("scrStart;scrLeft1;scrLeft2;scrLeft3;scrRight1;scrLeft4;scrInnerFinally;scrOuterFinally;".equals(primary.getValue("trace")) ||
                    "scrStart;scrLeft1;scrLeft2;scrLeft3;scrLeft4;scrOuterFinally;".equals(primary.getValue("trace")));
         assignmentList = Query.createRead(assignmentClass, null, Boolean.TRUE, null, -1, 0, false, Query.SEC_NONE, m_context).read();
         assertEquals(0, assignmentList.size());
         rollback();
      }
   }
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;
      Instance workflow, assignment;

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


      // Test: no exception
      primary.setValue("trace", null);
      primary.setValue("throwOuterEx", Boolean.FALSE);
      primary.setValue("throwUncaughtEx", Boolean.FALSE);
      primary.invoke("goSemaphore");
      assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary.getValue("trace"));
      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"));
      commit();
      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();
     


      // Test: caught exception
      primary.setValue("throwOuterEx", Boolean.TRUE);
      primary.setValue("throwUncaughtEx", Boolean.FALSE);
      primary.setValue("trace", null);
      primary.invoke("goSemaphore");
      assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary.getValue("trace"));
      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"));
      commit();
      assignment.invoke("schedulerRun");
      assertEquals(Instance.DELETED, assignment.getState());
      assertEquals(Instance.DELETED, workflow.getState());
      assertEquals(Primitive.createInteger(2), assignment.getValue("status"));
      assertEquals("BEFORE;ASSIGNMENT_CREATE;EXECUTE_SEMAPHORE;ASSIGNMENT_DELETE;CAUGHT_OUTER;", primary.getValue("trace"));
      commit();


      // Test: uncaught exception
      primary.setValue("throwOuterEx", Boolean.FALSE);
      primary.setValue("throwUncaughtEx", Boolean.TRUE);
      primary.setValue("trace", null);
      primary.invoke("goSemaphore");
      assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary.getValue("trace"));
      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

   {
      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;
      Instance workflow, assignment1, assignment2;
      List invocationList;

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


      /*
       * Test: Two semaphores in a fork.
       */
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(1000)));
      primary.setValue("trace", null);
      primary.setValue("throwInnerEx", Boolean.FALSE);
      primary.setValue("throwOuterEx", Boolean.FALSE);
      primary.invoke("goForkSemaphore");
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assignmentList = (InstanceList)workflow.getValue("assignments");
      assertEquals(2, assignmentList.size());
      assignment1 = assignmentList.getInstance(0);
      assignment2 = assignmentList.getInstance(1);

      if (assignment1.getValue("caption").equals("semaphoreRight:2"))
      {
         Instance temp = assignment1;

         assignment1 = assignment2;
         assignment2 = temp;
      }

      assertEquals("semaphoreLeftCaption", assignment1.getValue("caption"));
      assertEquals("semaphoreRight:2", assignment2.getValue("caption"));
      assertTrue(
         (assignment1.getValue("status").equals(Primitive.ONE_INTEGER) &&
         assignment2.getValue("status").equals(Primitive.ZERO_INTEGER)) ||
         (assignment1.getValue("status").equals(Primitive.ZERO_INTEGER) &&
         assignment2.getValue("status").equals(Primitive.ONE_INTEGER))
      );
      assertEquals(Boolean.TRUE, assignment1.getValue("semaphore"));
      assertEquals(Primitive.ONE_INTEGER, assignment1.getValue("status"));
      assertEquals(Boolean.TRUE, assignment2.getValue("semaphore"));
      assertEquals(Primitive.ZERO_INTEGER, assignment2.getValue("status"));
      invocationList = (List)schedulerClass.getValue("asyncInvokeList");
      assertEquals(1, invocationList.size());
      assertEquals(assignment1.getOID(), invocationList.get(0));

      // Simulate run of left semaphore
      assignment1.invoke("schedulerRun");
      assertEquals(Instance.DELETED, assignment1.getState());
      assertEquals(Instance.DIRTY, workflow.getState());
      assertEquals("scrStart;scrLeft1;", primary.getValue("trace"));

      // Left semaphore done, right semaphore should be running
      assertEquals(Boolean.TRUE, assignment2.getValue("semaphore"));
      assertEquals(Primitive.ONE_INTEGER, assignment2.getValue("status"));
      assertEquals(2, invocationList.size());
      assertEquals(assignment2.getOID(), invocationList.get(1));

      // Simulate run of right semaphore
      assignment2.invoke("schedulerRun");
      assertEquals(Instance.DELETED, assignment2.getState());
      assertEquals(Instance.DELETED, workflow.getState());
      assertEquals("scrStart;scrLeft1;scrRight1;scrFinish;", primary.getValue("trace"));
      commit();



      /*
       * Test: Two semaphores in a fork, left Semaphore throws exception
       */
      ((List)schedulerClass.getValue("asyncInvokeList")).clear();
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(1000)));
      primary.setValue("trace", null);
      primary.setValue("throwInnerEx", Boolean.TRUE);
      primary.setValue("throwOuterEx", Boolean.FALSE);
      primary.invoke("goForkSemaphore");
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assignmentList = (InstanceList)workflow.getValue("assignments");
      assertEquals(2, assignmentList.size());
      assignment1 = assignmentList.getInstance(0);
      assignment2 = assignmentList.getInstance(1);

      if (assignment1.getValue("caption").equals("semaphoreRight:2"))
      {
         Instance temp = assignment1;

         assignment1 = assignment2;
         assignment2 = temp;
      }

      assertEquals("semaphoreLeftCaption", assignment1.getValue("caption"));
      assertEquals("semaphoreRight:2", assignment2.getValue("caption"));
      assertTrue(
         (assignment1.getValue("status").equals(Primitive.ONE_INTEGER) &&
         assignment2.getValue("status").equals(Primitive.ZERO_INTEGER)) ||
         (assignment1.getValue("status").equals(Primitive.ZERO_INTEGER) &&
         assignment2.getValue("status").equals(Primitive.ONE_INTEGER))
      );
      assertEquals(Boolean.TRUE, assignment1.getValue("semaphore"));
      assertEquals(Primitive.ONE_INTEGER, assignment1.getValue("status"));
      assertEquals(Boolean.TRUE, assignment2.getValue("semaphore"));
      assertEquals(Primitive.ZERO_INTEGER, assignment2.getValue("status"));
      invocationList = (List)schedulerClass.getValue("asyncInvokeList");
      assertEquals(1, invocationList.size());
      assertEquals(assignment1.getOID(), invocationList.get(0));

      // Simulate run of left semaphore
      try
      {
         assignment1.invoke("schedulerRun");
         fail("No exception thrown");
      }
      catch (RuntimeException ex)
      {
         assertEquals(Instance.DELETED, assignment1.getState());
         assertEquals(Instance.DELETED, assignment2.getState());
         assertEquals("scrStart;scrLeft1;", primary.getValue("trace"));
         workflow.invoke("delete");
      }

      commit();



      /*
       * Test: Two semaphores in a fork, right (2nd) Semaphore throws exception
       */
      ((List)schedulerClass.getValue("asyncInvokeList")).clear();
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(1000)));
      primary.setValue("trace", null);
      primary.setValue("throwInnerEx", Boolean.FALSE);
      primary.setValue("throwOuterEx", Boolean.TRUE);
      primary.invoke("goForkSemaphore");
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary});
      assertEquals(1, workflowList.size());
      workflow = workflowList.getInstance(0);
      assignmentList = (InstanceList)workflow.getValue("assignments");
      assertEquals(2, assignmentList.size());
      assignment1 = assignmentList.getInstance(0);
      assignment2 = assignmentList.getInstance(1);

View Full Code Here

      Instance primary = (Instance)primaryClass.invoke("new");
      Instance primary2 = (Instance)primaryClass.invoke("new");
      Instance primary3 = (Instance)primaryClass.invoke("new");
      Instance primary4 = (Instance)primaryClass.invoke("new");
      Instance scheduler = (Instance)schedulerClass.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);
      primary4.setValue("trace", null);
      primary4.setValue("throwOuterEx", Boolean.FALSE);
      primary4.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");
      primary.invoke("goSemaphore");
      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));

      // Simulate run of Job
      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();


      /*
       * Test: Two jobs, queue concurrency = 1
       */
      ((List)schedulerClass.getValue("asyncInvokeList")).clear();
      primary.setValue("queueName", "SemaphoreLowConcurrency");
      primary2.setValue("queueName", "SemaphoreLowConcurrency");
      primary.setValue("trace", null);
      primary2.setValue("trace", null);
      primary.invoke("goSemaphore");
      Thread.sleep(50);
      primary2.invoke("goSemaphore");

      // Job 2: NOT 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.ZERO_INTEGER, assignment.getValue("status"));
      assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary2.getValue("trace"));

      // 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"));
      invocationList = (List)schedulerClass.getValue("asyncInvokeList");
      assertEquals(1, invocationList.size());
      assertEquals(assignment.getOID(), invocationList.get(0));

      // Simulate run 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"));

      // Job 1 finished, Job 2 should have been run
      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"));
      invocationList = (List)schedulerClass.getValue("asyncInvokeList");
      assertEquals(2, invocationList.size());
      assertEquals(assignment.getOID(), invocationList.get(1));

      // Simulate run 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();


      /*
       * Test: Four jobs. System concurrency: 2.
       * Job 1: Low concurrency queue    RUN...FINISH
       * Job 2: Low concurrency queue    WAIT       |           RUN...FINISH
       * Job 3: High concurrency queue   RUN........|.....FINISH^
       * Job 4: High concurrency queue   WAIT       RUN...........FINISH
       */
      ((List)schedulerClass.getValue("asyncInvokeList")).clear();
      primary.setValue("queueName", "SemaphoreLowConcurrency");
      primary2.setValue("queueName", "SemaphoreLowConcurrency");
      primary3.setValue("queueName", "Semaphore");
      primary4.setValue("queueName", "Semaphore");
      primary.setValue("trace", null);
      primary2.setValue("trace", null);
      primary3.setValue("trace", null);
      primary4.setValue("trace", null);
      primary.invoke("goSemaphore");
      Thread.sleep(50);
      primary2.invoke("goSemaphore");
      Thread.sleep(50);
      primary3.invoke("goSemaphore");
      Thread.sleep(50);
      primary4.invoke("goSemaphore");


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

      // Job 4: NOT RUNNING
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary4});
      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;", primary4.getValue("trace"));

      // Job 2: NOT 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.ZERO_INTEGER, assignment.getValue("status"));
      assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary2.getValue("trace"));

      // Job 3: 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.ONE_INTEGER, assignment.getValue("status"));
      assertEquals(assignment.getOID(), invocationList.get(1));

      // 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();

      // Job 2 or 4 could run: 4 runs because its queue has higher priority
      assertEquals(3, invocationList.size());

      // Job 4: RUNNING
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary4});
      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));

      // Job 2: NOT 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.ZERO_INTEGER, assignment.getValue("status"));
      assertEquals("BEFORE;ASSIGNMENT_CREATE;", primary2.getValue("trace"));
     
      // Job 3: 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.ONE_INTEGER, assignment.getValue("status"));
      assertEquals(assignment.getOID(), invocationList.get(1));

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

      // Job 2 runs
      assertEquals(4, invocationList.size());

      // 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(assignment.getOID(), invocationList.get(3));
     
      // Job 4: RUNNING
      workflowList = (InstanceList)workflowClass.invoke("forInstance",
         new Object[]{primary4});
      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));

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

      // 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(assignment.getOID(), invocationList.get(3));

      // 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"));
      assertEquals(4, invocationList.size());


      /*
       * Test: One job, outside of time window.
       */
      ((List)schedulerClass.getValue("asyncInvokeList")).clear();
      schedulerClass.setValue("time", Primitive.toTimestamp(Primitive.createInteger(15000)));
      primary.setValue("trace", null);
      primary.setValue("queueName", "Semaphore");
      primary.invoke("goSemaphore");
      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

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.