DefaultAgentCache implements AgentCache { @Override public Set<AgentInstance> getAgentInstances(String instanceGroupId) { return AgentManagementException.checkInstanceGroupFound(dataSnapshot.getInstances(instanceGroupId), instanceGroupId); } @Inject  DefaultAgentCache(AgentManagementConfiguration configuration,
                             AgentStore agentStore,
                             InstanceCloudConnector connector,
                             Registry registry);   DefaultAgentCache(AgentManagementConfiguration configuration,
                      AgentStore agentStore,
                      InstanceCloudConnector connector,
                      Registry registry,
                      Scheduler scheduler); @Activator void enterActiveMode(); void shutdown(); @Override List<AgentInstanceGroup> getInstanceGroups(); @Override AgentInstanceGroup getInstanceGroup(String instanceGroupId); @Override Optional<AgentInstanceGroup> findInstanceGroup(String instanceGroupId); @Override Set<AgentInstance> getAgentInstances(String instanceGroupId); @Override AgentInstance getAgentInstance(String instanceId); @Override Optional<AgentInstance> findAgentInstance(String instanceId); @Override Single<AgentInstanceGroup> updateInstanceGroupStore(String instanceGroupId, Function<AgentInstanceGroup, AgentInstanceGroup> function); @Override Single<AgentInstanceGroup> updateInstanceGroupStoreAndSyncCloud(String instanceGroupId, Function<AgentInstanceGroup, AgentInstanceGroup> function); @Override Single<AgentInstance> updateAgentInstanceStore(String instanceId, Function<AgentInstance, AgentInstance> function); @Override Completable removeInstances(String instanceGroupId, Set<String> agentInstanceIds); @Override Observable<CacheUpdateEvent> events();  }
@Test public void testDiscoverNewAgentInstance() { String instanceGroupId = testConnector.takeInstanceGroup(0).getId(); int initialCount = cache.getAgentInstances(instanceGroupId).size(); instanceGenerator1 = instanceGenerator1.apply(testConnector::addInstance); testScheduler.advanceTimeBy(CACHE_REFRESH_INTERVAL_MS, TimeUnit.MILLISECONDS); assertThat(cache.getAgentInstances(instanceGroupId).size()).isEqualTo(initialCount + 1); expectInstanceGroupUpdateEvent(eventSubscriber, instanceGroupId); }
@Test public void testCleanupOfRemovedAgentInstance() { String instanceGroupId = testConnector.takeInstanceGroup(0).getId(); int initialCount = cache.getAgentInstances(instanceGroupId).size(); testConnector.removeInstance(testConnector.takeInstance(0, 0).getId()); testScheduler.advanceTimeBy(CACHE_REFRESH_INTERVAL_MS, TimeUnit.MILLISECONDS); assertThat(cache.getAgentInstances(instanceGroupId).size()).isEqualTo(initialCount - 1); expectInstanceGroupUpdateEvent(eventSubscriber, instanceGroupId); }