Skip to content

Commit

Permalink
Merge pull request eclipse-archived#1255 from sjka/fixInboxTest
Browse files Browse the repository at this point in the history
fixed InboxOSGiTest timing issues
  • Loading branch information
maggu2810 authored and cdjackson committed Mar 28, 2016
2 parents d684359 + 1f79ccc commit e6595e9
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -632,18 +632,23 @@ class InboxOSGITest extends OSGiTest {

@Test
void 'assert that remove removes associated DiscoveryResults from Inbox when Bridge is removed'() {
inbox.add(BRIDGE)
inbox.add(THING1_WITH_BRIDGE)
inbox.add(THING2_WITH_BRIDGE)
inbox.add(THING_WITHOUT_BRIDGE)
inbox.add(THING_WITH_OTHER_BRIDGE)
def receivedEvents = new ArrayList()
def inboxEventSubscriber = [
receive: { event -> receivedEvents.add(event) },
getSubscribedEventTypes: { Sets.newHashSet(InboxAddedEvent.TYPE, InboxRemovedEvent.TYPE, InboxUpdatedEvent.TYPE) },
getEventFilter: { null },
] as EventSubscriber
registerService inboxEventSubscriber
inbox.add(BRIDGE)
inbox.add(THING1_WITH_BRIDGE)
inbox.add(THING2_WITH_BRIDGE)
inbox.add(THING_WITHOUT_BRIDGE)
inbox.add(THING_WITH_OTHER_BRIDGE)
waitForAssert {
assertThat receivedEvents.size(), is(5)
}
receivedEvents.clear()

assertTrue inbox.remove(BRIDGE.thingUID)
assertTrue inbox.get(new InboxFilterCriteria(BRIDGE.thingUID, DiscoveryResultFlag.NEW)).isEmpty()
assertTrue inbox.get(new InboxFilterCriteria(THING1_WITH_BRIDGE.thingUID, DiscoveryResultFlag.NEW)).isEmpty()
Expand All @@ -659,17 +664,22 @@ class InboxOSGITest extends OSGiTest {

@Test
void 'assert that remove leaves associated DiscoveryResults in Inbox when Bridge is added to ThingRegistry'() {
inbox.add(BRIDGE)
inbox.add(THING1_WITH_BRIDGE)
inbox.add(THING2_WITH_BRIDGE)
inbox.add(THING_WITHOUT_BRIDGE)
def receivedEvents = new ArrayList()
def inboxEventSubscriber = [
receive: { event -> receivedEvents.add(event) },
getSubscribedEventTypes: { Sets.newHashSet(InboxAddedEvent.TYPE, InboxRemovedEvent.TYPE, InboxUpdatedEvent.TYPE) },
getEventFilter: { null },
] as EventSubscriber
registerService inboxEventSubscriber
inbox.add(BRIDGE)
inbox.add(THING1_WITH_BRIDGE)
inbox.add(THING2_WITH_BRIDGE)
inbox.add(THING_WITHOUT_BRIDGE)
waitForAssert {
assertThat receivedEvents.size(), is(4)
}
receivedEvents.clear()

registry.add(BridgeBuilder.create(BRIDGE.thingUID).build())
assertTrue inbox.get(new InboxFilterCriteria(BRIDGE.thingUID, DiscoveryResultFlag.NEW)).isEmpty()
assertThat inbox.get(new InboxFilterCriteria(DiscoveryResultFlag.NEW)), hasItems(THING1_WITH_BRIDGE,THING2_WITH_BRIDGE,THING_WITHOUT_BRIDGE)
Expand Down

0 comments on commit e6595e9

Please sign in to comment.