/** * @return Returns class cache based on the {@link AgentCacheEntry}. */ protected ClassCache getClassCache() { return agentCacheEntry.getClassCache(); }
/** * @return Returns configuration holder based on the {@link AgentCacheEntry}. */ protected ConfigurationHolder getConfigurationHolder() { return agentCacheEntry.getConfigurationHolder(); }
/** * @return Returns agent id based on the {@link AgentCacheEntry}. */ protected long getAgentId() { return agentCacheEntry.getId(); }
@BeforeMethod public void init() throws Exception { MockitoAnnotations.initMocks(this); job.log = LoggerFactory.getLogger(EnvironmentMappingUpdateJob.class); job.setAgentCacheEntry(agentCacheEntry); when(configurationHolder.getEnvironment()).thenReturn(environment); when(configurationHolder.getInstrumentationAppliers()).thenReturn(Collections.singletonList(holdedInstrumentationApplier)); when(agentCacheEntry.getConfigurationHolder()).thenReturn(configurationHolder); when(agentCacheEntry.getClassCache()).thenReturn(classCache); when(agentCacheEntry.getId()).thenReturn(PLATFORM_ID); when(classCache.getInstrumentationService()).thenReturn(instrumentationService); when(classCache.getLookupService()).thenReturn(lookupService); when(classType.isClass()).thenReturn(true); when(classType.castToClass()).thenReturn(immutableClassType); }
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void successful() throws BusinessException, InterruptedException, ExecutionException, TimeoutException { cacheMap.put(1L, cacheEntry); when(cacheEntry.getId()).thenReturn(10L); when(configurationResolver.getEnvironmentForAgent(any(List.class), any(String.class))).thenReturn(newEnvironment); when(cachedEnvironment.getId()).thenReturn("id"); when(newEnvironment.getId()).thenReturn("newId"); when(objectFactory.getObject()).thenReturn(updateJob); when(executor.submit(updateJob)).thenReturn((Future) future); eventListener.onApplicationEvent(event); verify(nextGenInstrumentationManager).getAgentCacheMap(); verify(cacheEntry).getConfigurationHolder(); verify(cacheEntry).getId(); verify(configurationHolder).getEnvironment(); verify(platformIdentDao).load(10L); verify(platformIdent).getAgentName(); verify(platformIdent).getDefinedIPs(); verify(configurationResolver).getEnvironmentForAgent(any(List.class), any(String.class)); verify(cachedEnvironment).getId(); verify(newEnvironment).getId(); verify(objectFactory).getObject(); verify(updateJob).setAgentCacheEntry(cacheEntry); verify(updateJob).setEnvironment(newEnvironment); verify(executor).submit(updateJob); verify(future).get(1L, TimeUnit.MINUTES); verifyNoMoreInteractions(nextGenInstrumentationManager, cacheEntry, configurationHolder, platformIdentDao, platformIdent, configurationResolver, cachedEnvironment, newEnvironment, event, objectFactory, updateJob, executor, future); }
ClassCache classCache = agentCacheEntry.getClassCache(); ImmutableType type = classCache.getLookupService().findByHash(hash); ConfigurationHolder configurationHolder = agentCacheEntry.getConfigurationHolder();
/** * Returns agent cache entry for the agent. * * @param platformIdent * Agent id. * @return {@link AgentCacheEntry} */ private AgentCacheEntry getAgentCacheEntry(long platformIdent) { AgentCacheEntry agentCacheEntry = agentCacheMap.get(Long.valueOf(platformIdent)); if (null == agentCacheEntry) { ClassCache classCache = classCacheFactory.getObject(); ConfigurationHolder configurationHolder = configurationHolderFactory.getObject(); agentCacheEntry = new AgentCacheEntry(platformIdent, classCache, configurationHolder); AgentCacheEntry existing = agentCacheMap.putIfAbsent(Long.valueOf(platformIdent), agentCacheEntry); if (null != existing) { agentCacheEntry = existing; } } return agentCacheEntry; }
@BeforeMethod public void setup() throws Exception { when(configurationHolder.getAgentConfiguration()).thenReturn(agentConfiguration); when(configurationHolder.getEnvironment()).thenReturn(environment); when(configurationHolder.getInstrumentationAppliers()).thenReturn(Collections.singletonList(holdedInstrumentationApplier)); when(agentCacheEntry.getConfigurationHolder()).thenReturn(configurationHolder); when(agentCacheEntry.getClassCache()).thenReturn(classCache); when(agentCacheEntry.getId()).thenReturn(PLATFORM_ID); when(classCache.getInstrumentationService()).thenReturn(instrumentationService); when(classType.isClass()).thenReturn(true); when(classType.castToClass()).thenReturn(immutableClassType); when(classType.getFQN()).thenReturn("fqn"); when(event.getAfter()).thenReturn(updateEnvironment); }
ConfigurationHolder configurationHolder = agentCacheEntry.getConfigurationHolder(); Environment cachedEnvironment = configurationHolder.getEnvironment(); PlatformIdent platformIdent = platformIdentDao.load(agentCacheEntry.getId()); try {
ClassCache classCache = agentCacheEntry.getClassCache(); ConfigurationHolder configurationHolder = agentCacheEntry.getConfigurationHolder();
@BeforeMethod public void setup() throws Exception { when(configurationHolder.getAgentConfiguration()).thenReturn(agentConfiguration); when(configurationHolder.getEnvironment()).thenReturn(environment); when(configurationHolder.getInstrumentationAppliers()).thenReturn(Collections.singletonList(holdedInstrumentationApplier)); when(agentCacheEntry.getConfigurationHolder()).thenReturn(configurationHolder); when(agentCacheEntry.getClassCache()).thenReturn(classCache); when(agentCacheEntry.getId()).thenReturn(10L); when(classCache.getInstrumentationService()).thenReturn(instrumentationService); when(classTypeOne.isClass()).thenReturn(true); when(classTypeTwo.isClass()).thenReturn(true); when(classTypeOne.castToClass()).thenReturn(immutableClassTypeOne); when(classTypeTwo.castToClass()).thenReturn(immutableClassTypeTwo); when(immutableClassTypeOne.hasInstrumentationPoints()).thenReturn(true); when(immutableClassTypeOne.hasInstrumentationPoints()).thenReturn(false); when(classTypeOne.getFQN()).thenReturn("fqnOne"); when(classTypeTwo.getFQN()).thenReturn("fqnTwo"); }
@BeforeMethod public void beforeMethod() { cacheMap = new HashMap<>(); when(nextGenInstrumentationManager.getAgentCacheMap()).thenReturn(cacheMap); when(cacheEntry.getConfigurationHolder()).thenReturn(configurationHolder); when(configurationHolder.getEnvironment()).thenReturn(environment); }
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void futureThrowsExecutionException() throws InterruptedException, ExecutionException, BusinessException, TimeoutException { cacheMap.put(1L, cacheEntry); when(cacheEntry.getId()).thenReturn(10L); when(configurationResolver.getEnvironmentForAgent(any(List.class), any(String.class))).thenReturn(newEnvironment); when(cachedEnvironment.getId()).thenReturn("id"); when(newEnvironment.getId()).thenReturn("newId"); when(objectFactory.getObject()).thenReturn(updateJob); when(executor.submit(updateJob)).thenReturn((Future) future); when(future.get(1L, TimeUnit.MINUTES)).thenThrow(ExecutionException.class); eventListener.onApplicationEvent(event); verify(future).get(1L, TimeUnit.MINUTES); }
@BeforeMethod public void beforeMethod() { cacheMap = new HashMap<>(); when(nextGenInstrumentationManager.getAgentCacheMap()).thenReturn(cacheMap); when(cacheEntry.getConfigurationHolder()).thenReturn(configurationHolder); when(configurationHolder.getEnvironment()).thenReturn(environment); }
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void futureThrowsInterruptedException() throws InterruptedException, ExecutionException, BusinessException, TimeoutException { cacheMap.put(1L, cacheEntry); when(cacheEntry.getId()).thenReturn(10L); when(configurationResolver.getEnvironmentForAgent(any(List.class), any(String.class))).thenReturn(newEnvironment); when(cachedEnvironment.getId()).thenReturn("id"); when(newEnvironment.getId()).thenReturn("newId"); when(objectFactory.getObject()).thenReturn(updateJob); when(executor.submit(updateJob)).thenReturn((Future) future); when(future.get(1L, TimeUnit.MINUTES)).thenThrow(InterruptedException.class); eventListener.onApplicationEvent(event); verify(future).get(1L, TimeUnit.MINUTES); } }
ConfigurationHolder configurationHolder = agentCacheEntry.getConfigurationHolder();
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void noEnvironmentAssigned() throws InterruptedException, ExecutionException, BusinessException, TimeoutException { cacheMap.put(1L, cacheEntry); when(cacheEntry.getId()).thenReturn(10L); when(configurationHolder.getEnvironment()).thenReturn(null); when(configurationResolver.getEnvironmentForAgent(any(List.class), any(String.class))).thenReturn(newEnvironment); when(cachedEnvironment.getId()).thenReturn("id"); when(newEnvironment.getId()).thenReturn("newId"); when(objectFactory.getObject()).thenReturn(updateJob); when(executor.submit(updateJob)).thenReturn((Future) future); eventListener.onApplicationEvent(event); verify(configurationHolder).getEnvironment(); verify(future).get(1L, TimeUnit.MINUTES); verifyNoMoreInteractions(configurationHolder, future); }
@BeforeMethod public void beforeMethod() { cacheMap = new HashMap<>(); when(nextGenInstrumentationManager.getAgentCacheMap()).thenReturn(cacheMap); when(cacheEntry.getConfigurationHolder()).thenReturn(configurationHolder); when(configurationHolder.getEnvironment()).thenReturn(cachedEnvironment); when(platformIdentDao.load(10L)).thenReturn(platformIdent); }
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void resolverThrowsBusinessException() throws BusinessException, InterruptedException, ExecutionException, TimeoutException { cacheMap.put(1L, cacheEntry); when(cacheEntry.getId()).thenReturn(10L); when(configurationResolver.getEnvironmentForAgent(any(List.class), any(String.class))).thenThrow(BusinessException.class); when(cachedEnvironment.getId()).thenReturn("id"); when(newEnvironment.getId()).thenReturn("newId"); when(objectFactory.getObject()).thenReturn(updateJob); when(executor.submit(updateJob)).thenReturn((Future) future); eventListener.onApplicationEvent(event); verify(configurationResolver).getEnvironmentForAgent(any(List.class), any(String.class)); verify(objectFactory).getObject(); verify(updateJob).setAgentCacheEntry(cacheEntry); verify(executor).submit(updateJob); verify(future).get(1L, TimeUnit.MINUTES); verifyNoMoreInteractions(configurationResolver, objectFactory, updateJob, executor, future); verifyZeroInteractions(cachedEnvironment, newEnvironment); }
@Test public void configurationNotInitialized() { cacheMap.put(1L, cacheEntry); when(configurationHolder.isInitialized()).thenReturn(false); eventListener.onApplicationEvent(event); verify(nextGenInstrumentationManager).getAgentCacheMap(); verify(cacheEntry).getConfigurationHolder(); verify(configurationHolder).isInitialized(); verifyNoMoreInteractions(nextGenInstrumentationManager, cacheEntry, configurationHolder); verifyZeroInteractions(environment, event, objectFactory, updateJob, executor, future); }