/** * @return Returns agent id based on the {@link AgentCacheEntry}. */ protected long getAgentId() { return agentCacheEntry.getId(); }
@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); }
@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); } }
@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 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); }
@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 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); }
@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"); }
@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); }
ConfigurationHolder configurationHolder = agentCacheEntry.getConfigurationHolder(); Environment cachedEnvironment = configurationHolder.getEnvironment(); PlatformIdent platformIdent = platformIdentDao.load(agentCacheEntry.getId()); try {