コード例 #1
0
  @Test
  public final void testMarkOffline() {

    putDevice(DID1, SW1);
    assertTrue(deviceStore.isAvailable(DID1));

    Capture<InternalDeviceEvent> message = new Capture<>();
    Capture<MessageSubject> subject = new Capture<>();
    Capture<Function<InternalDeviceEvent, byte[]>> encoder = new Capture<>();

    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    DeviceEvent event = deviceStore.markOffline(DID1);
    assertEquals(DEVICE_AVAILABILITY_CHANGED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertFalse(deviceStore.isAvailable(DID1));
    verify(clusterCommunicator);
    // TODO: verify broadcast message
    assertTrue(message.hasCaptured());

    resetCommunicatorExpectingNoBroadcast(message, subject, encoder);
    DeviceEvent event2 = deviceStore.markOffline(DID1);
    assertNull("No change, no event", event2);
    verify(clusterCommunicator);
    assertFalse(message.hasCaptured());
  }
コード例 #2
0
  @Test
  public final void testCreateOrUpdateDeviceAncillary() throws IOException {
    // add
    DeviceDescription description =
        new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID, A2);
    Capture<ClusterMessage> bcast = new Capture<>();

    Capture<InternalDeviceEvent> message = new Capture<>();
    Capture<MessageSubject> subject = new Capture<>();
    Capture<Function<InternalDeviceEvent, byte[]>> encoder = new Capture<>();

    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);
    DeviceEvent event = deviceStore.createOrUpdateDevice(PIDA, DID1, description);
    assertEquals(DEVICE_ADDED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertEquals(PIDA, event.subject().providerId());
    assertAnnotationsEquals(event.subject().annotations(), A2);
    assertFalse("Ancillary will not bring device up", deviceStore.isAvailable(DID1));
    verify(clusterCommunicator);
    assertInternalDeviceEvent(NID1, DID1, PIDA, description, message, subject, encoder);

    // update from primary
    DeviceDescription description2 =
        new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW2, SN, CID, A1);
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);

    DeviceEvent event2 = deviceStore.createOrUpdateDevice(PID, DID1, description2);
    assertEquals(DEVICE_UPDATED, event2.type());
    assertDevice(DID1, SW2, event2.subject());
    assertEquals(PID, event2.subject().providerId());
    assertAnnotationsEquals(event2.subject().annotations(), A1, A2);
    assertTrue(deviceStore.isAvailable(DID1));
    verify(clusterCommunicator);
    assertInternalDeviceEvent(NID1, DID1, PID, description2, message, subject, encoder);

    // no-op update from primary
    resetCommunicatorExpectingNoBroadcast(message, subject, encoder);
    assertNull("No change expected", deviceStore.createOrUpdateDevice(PID, DID1, description2));

    verify(clusterCommunicator);
    assertFalse("no broadcast expected", bcast.hasCaptured());

    // For now, Ancillary is ignored once primary appears
    resetCommunicatorExpectingNoBroadcast(message, subject, encoder);

    assertNull("No change expected", deviceStore.createOrUpdateDevice(PIDA, DID1, description));

    verify(clusterCommunicator);
    assertFalse("no broadcast expected", bcast.hasCaptured());

    // But, Ancillary annotations will be in effect
    DeviceDescription description3 =
        new DefaultDeviceDescription(DID1.uri(), SWITCH, MFR, HW, SW1, SN, CID, A2_2);
    resetCommunicatorExpectingSingleBroadcast(message, subject, encoder);

    DeviceEvent event3 = deviceStore.createOrUpdateDevice(PIDA, DID1, description3);
    assertEquals(DEVICE_UPDATED, event3.type());
    // basic information will be the one from Primary
    assertDevice(DID1, SW2, event3.subject());
    assertEquals(PID, event3.subject().providerId());
    // but annotation from Ancillary will be merged
    assertAnnotationsEquals(event3.subject().annotations(), A1, A2, A2_2);
    assertTrue(deviceStore.isAvailable(DID1));
    verify(clusterCommunicator);
    // note: only annotation from PIDA is sent over the wire
    assertInternalDeviceEvent(
        NID1, DID1, PIDA, description3, asList(union(A2, A2_2)), message, subject, encoder);
  }