InstanceCache { List<InstanceGroup> getInstanceGroups() { return cacheSnapshot.getInstanceGroups(); } private  InstanceCache(AgentManagementConfiguration configuration,
                          InstanceCloudConnector connector,
                          Set<String> knownInstanceGroups,
                          Registry registry,
                          int bootRetryCount,
                          long bootRetryDelayMs,
                          Scheduler scheduler);   }
@Test public void testBootstrapWithoutKnownInstanceGroups() { assertThat(instanceGroupIds(cache.getInstanceGroups())).containsAll(testConnector.takeInstanceGroupIds()); InstanceGroup firstInstanceGroup = testConnector.takeInstanceGroup(0); assertThat(cache.getInstanceGroups()).contains(firstInstanceGroup); assertThat(firstInstanceGroup.getInstanceIds()).containsAll(instanceIds(testConnector.takeInstances(0))); InstanceGroup secondInstanceGroup = testConnector.takeInstanceGroup(1); assertThat(cache.getInstanceGroups()).contains(secondInstanceGroup); assertThat(secondInstanceGroup.getInstanceIds()).containsAll(instanceIds(testConnector.takeInstances(1))); testScheduler.advanceTimeBy(CACHE_REFRESH_INTERVAL_MS, TimeUnit.MILLISECONDS); assertThat(eventSubscriber.takeNext()).isNull(); }
@Test public void testInstanceGroupAdded() { int initialCount = cache.getInstanceGroups().size(); instanceGroupsGenerator = instanceGroupsGenerator.apply(testConnector::addInstanceGroup); testScheduler.advanceTimeBy(FULL_CACHE_REFRESH_INTERVAL_MS, TimeUnit.MILLISECONDS); InstanceGroup instanceGroup = CollectionsExt.last(testConnector.getInstanceGroups().toBlocking().singleOrDefault(Collections.emptyList())); assertThat(cache.getInstanceGroups()).hasSize(initialCount + 1); expectInstanceGroupAddedEvent(eventSubscriber, instanceGroup.getId()); }