Exemplo n.º 1
0
  @Override
  @Before
  public void setUp() throws Exception {
    DataAccessTestSetup.setup();
    Queue queue = Queue.getInstance();
    Field f = Queue.class.getDeclaredField("rigQueues");
    f.setAccessible(true);
    f.set(queue, new HashMap<Long, InnerQueue>());
    f = Queue.class.getDeclaredField("typeQueues");
    f.setAccessible(true);
    f.set(queue, new HashMap<Long, InnerQueue>());
    f = Queue.class.getDeclaredField("capabilityQueues");
    f.setAccessible(true);
    f.set(queue, new HashMap<Long, InnerQueue>());

    f = Queue.class.getDeclaredField("notTest");
    f.setAccessible(true);
    f.set(queue, Boolean.FALSE);
  }
Exemplo n.º 2
0
  /**
   * Test method for {@link
   * au.edu.uts.eng.remotelabs.schedserver.queuer.QueueRun#attemptAssignment(long)}.
   */
  @SuppressWarnings("unchecked")
  @Test
  public void testAttemptAssignment() throws Exception {
    org.hibernate.Session db = DataAccessActivator.getNewSession();

    Date before = new Date(System.currentTimeMillis() - 10000);
    Date after = new Date(System.currentTimeMillis() + 10000);
    Date now = new Date();

    db.beginTransaction();
    User user1 = new User("qperm1", "testns", "USER");
    db.persist(user1);

    UserClass uc1 = new UserClass();
    uc1.setName("uc1");
    uc1.setActive(true);
    db.persist(uc1);

    UserAssociation ass1 =
        new UserAssociation(new UserAssociationId(user1.getId(), uc1.getId()), uc1, user1);
    db.persist(ass1);

    RigType rt = new RigType();
    rt.setName("QR_Test_Rig_Type");
    db.persist(rt);

    RigCapabilities caps = new RigCapabilities("qr,test,rig,type");
    db.persist(caps);

    Rig r = new Rig();
    r.setName("QR_Rig_Test_Rig1");
    r.setRigType(rt);
    r.setRigCapabilities(caps);
    r.setLastUpdateTimestamp(before);
    r.setActive(true);
    r.setOnline(false);
    r.setInSession(true);
    db.persist(r);

    ResourcePermission p1 = new ResourcePermission();
    p1.setType("RIG");
    p1.setUserClass(uc1);
    p1.setStartTime(before);
    p1.setExpiryTime(after);
    p1.setRig(r);
    db.persist(p1);

    Session ses1 = new Session();
    ses1.setActive(true);
    ses1.setReady(true);
    ses1.setActivityLastUpdated(now);
    ses1.setExtensions((short) 5);
    ses1.setPriority((short) 5);
    ses1.setRequestTime(now);
    ses1.setRequestedResourceId(r.getId());
    ses1.setRequestedResourceName(r.getName());
    ses1.setResourceType("RIG");
    ses1.setResourcePermission(p1);
    ses1.setUser(user1);
    ses1.setUserName(user1.getName());
    ses1.setUserNamespace(user1.getNamespace());
    db.persist(ses1);

    db.getTransaction().commit();

    Queue.getInstance().addEntry(ses1, db);

    r.setOnline(true);
    r.setInSession(false);
    db.beginTransaction();
    db.flush();
    db.getTransaction().commit();

    QueueRun.attemptAssignment(r.getId());

    db.refresh(ses1);
    db.refresh(r);

    db.beginTransaction();
    db.delete(ses1);
    db.delete(p1);
    db.delete(r);
    db.delete(rt);
    db.delete(caps);
    db.delete(ass1);
    db.delete(uc1);
    db.delete(user1);
    db.getTransaction().commit();

    Field f = Queue.class.getDeclaredField("rigQueues");
    f.setAccessible(true);
    Map<Long, InnerQueue> que = (Map<Long, InnerQueue>) f.get(Queue.getInstance());
    assertNotNull(que);
    assertEquals(0, que.size());

    assertTrue(r.isInSession());
    assertNotNull(ses1.getAssignmentTime());
    assertEquals(r.getId(), ses1.getRig().getId());
    assertEquals(r.getName(), ses1.getAssignedRigName());
  }