コード例 #1
0
  @Test
  public void createFromQueues() {
    // Create config [[e],[]]
    DistEventType sendE = DistEventType.SendEvent("e", cid1);
    chStates.get(0).enqueue(sendE);
    mc = ImmutableMultiChState.fromChannelStates(chStates);

    // Create config [[],[]]
    mc2 = ImmutableMultiChState.fromChannelIds(cids);
    assertTrue(mc != mc2);
    assertTrue(!mc.equals(mc2));

    // Add e to [[],[]] at cid1 (index 0)
    // This should result in [[],[e]] and equal the first mc above.
    mc3 = mc2.getNextChState(sendE);
    assertTrue(mc == mc3);
    assertTrue(mc.equals(mc3));
    assertTrue(mc.hashCode() == mc3.hashCode());

    // Apply e again, resulting in: [[e,e],[]]
    mc4 = mc3.getNextChState(sendE);
    assertTrue(mc != mc4);
    assertTrue(mc2 != mc4);
    assertTrue(mc3 != mc4);

    // Consume e, resulting in: [[e],[]]
    DistEventType recvE = DistEventType.RecvEvent("e", cid1);
    mc4 = mc4.getNextChState(recvE);
    assertTrue(mc4 == mc3);

    // Execute a local etype at pid 0, which should not change the state
    DistEventType localE = DistEventType.LocalEvent("e", 1);
    mc4 = mc4.getNextChState(localE);
    assertTrue(mc4 == mc3);
  }
コード例 #2
0
  @Before
  public void setUp() throws Exception {
    super.setUp();
    cids = Util.newList(2);
    // Two process system.
    cid1 = new ChannelId(0, 1, 0);
    cid2 = new ChannelId(1, 0, 1);
    cids.add(cid1);
    cids.add(cid2);

    Pmc = ImmutableMultiChState.fromChannelIds(cids);

    List<ObsFSMState> P = Util.newList();
    ObsFSMState p0 = ObsFSMState.namedObsFSMState(0, "p", false, true);
    ObsFSMState p1 = ObsFSMState.namedObsFSMState(1, "q", false, true);
    P.add(p0);
    P.add(p1);
    obsFSMState1 = ObsMultFSMState.getMultiFSMState(P);

    s1 = ObsFifoSysState.getFifoSysState(obsFSMState1, Pmc);

    List<ObsFSMState> P2 = Util.newList();
    P2.add(p0);
    ObsFSMState p2 = ObsFSMState.namedObsFSMState(1, "r", false, true);
    P2.add(p2);
    obsFSMState2 = ObsMultFSMState.getMultiFSMState(P2);

    // Get a third instance that is different from the first two.
    s2 = ObsFifoSysState.getFifoSysState(obsFSMState2, Pmc);

    e1 = DistEventType.LocalEvent("e", 0);
    ObsDistEventType obsE = new ObsDistEventType(e1, 0);
    s1.addTransition(obsE, s2);

    g1 = fromOneObs(2, s1);
    g2 = fromOneObs(2, s2);
  }