InstrumentationKeyResolver() { this.appIdCache = new ConcurrentHashMap<String, String>(); this.profileFetcher = new CdsProfileFetcher(); }
currentTask = createFetchTask(instrumentationKey); this.tasks.putIfAbsent(instrumentationKey, currentTask); incrementFailureCount(instrumentationKey); return new ProfileFetcherResult(null, ProfileFetcherResultTaskStatus.FAILED); incrementFailureCount(instrumentationKey); return new ProfileFetcherResult(null, ProfileFetcherResultTaskStatus.FAILED); incrementFailureCount(instrumentationKey); throw ex;
@Test(expected = ExecutionException.class) public void testFetchApplicationIdFailureWithException() throws InterruptedException, ExecutionException, ParseException, IOException { //setup - mimic timeout from the async http call MockHttpAsyncClientWrapper clientWrapper = new MockHttpAsyncClientWrapper(); clientWrapper.setAppId("AppId"); CdsProfileFetcher fetcher = new CdsProfileFetcher(); fetcher.setHttpClient(clientWrapper.getClient()); // the first time we try to fetch the profile, we should get a "pending" task status // since the profile fetcher uses asynchronous calls to retrieve the profile from CDS ProfileFetcherResult result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.PENDING, result.getStatus()); Assert.assertNull(result.getAppId()); // instruct mock task to fail clientWrapper.setFailureOn(true); clientWrapper.setTaskAsComplete(); result = fetcher.fetchAppProfile("ikey"); Assert.fail("Should not have reached here. Instead, an exception should have been thrown."); }
public CdsProfileFetcher() { RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(5000) .setConnectTimeout(5000) .setConnectionRequestTimeout(5000) .build(); setHttpClient(HttpAsyncClients.custom() .setDefaultRequestConfig(requestConfig) .useSystemProperties() .build()); this.httpClient.start(); this.tasks = new ConcurrentHashMap<String, Future<HttpResponse>>(); this.failureCounters = new HashMap<String, Integer>(); this.endpointAddress = DefaultProfileQueryEndpointAddress; }
@Test public void testFetchApplicationIdWithTaskCompleteImmediately() throws InterruptedException, ExecutionException, ParseException, IOException { //setup MockHttpAsyncClientWrapper clientWrapper = new MockHttpAsyncClientWrapper(); clientWrapper.setAppId("AppId"); clientWrapper.setFailureOn(false); clientWrapper.setTaskAsComplete(); CdsProfileFetcher fetcher = new CdsProfileFetcher(); fetcher.setHttpClient(clientWrapper.getClient()); // task is completed right away ProfileFetcherResult result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.COMPLETE, result.getStatus()); Assert.assertEquals("AppId", result.getAppId()); }
public CdsProfileFetcher() { RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(5000) .setConnectTimeout(5000) .setConnectionRequestTimeout(5000) .build(); setHttpClient(HttpAsyncClients.custom() .setDefaultRequestConfig(requestConfig) .useSystemProperties() .build()); this.httpClient.start(); this.tasks = new ConcurrentHashMap<String, Future<HttpResponse>>(); this.failureCounters = new HashMap<String, Integer>(); this.endpointAddress = DefaultProfileQueryEndpointAddress; }
@Test public void testFetchApplicationId() throws InterruptedException, ExecutionException, ParseException, IOException { //setup MockHttpAsyncClientWrapper clientWrapper = new MockHttpAsyncClientWrapper(); clientWrapper.setAppId("AppId"); clientWrapper.setFailureOn(false); CdsProfileFetcher fetcher = new CdsProfileFetcher(); fetcher.setHttpClient(clientWrapper.getClient()); // the first time we try to fetch the profile, we might get a "pending" task status // since the profile fetcher uses asynchronous calls to retrieve the profile from CDS // this is mimic'ed with clientWrapper.setTaskAsPending(); clientWrapper.setTaskAsPending(); ProfileFetcherResult result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.PENDING, result.getStatus()); Assert.assertNull(result.getAppId()); // mimic task completion clientWrapper.setTaskAsComplete(); result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.COMPLETE, result.getStatus()); Assert.assertEquals("AppId", result.getAppId()); }
currentTask = createFetchTask(instrumentationKey); this.tasks.putIfAbsent(instrumentationKey, currentTask); incrementFailureCount(instrumentationKey); return new ProfileFetcherResult(null, ProfileFetcherResultTaskStatus.FAILED); incrementFailureCount(instrumentationKey); return new ProfileFetcherResult(null, ProfileFetcherResultTaskStatus.FAILED); incrementFailureCount(instrumentationKey); throw ex;
InstrumentationKeyResolver() { this.appIdCache = new ConcurrentHashMap<String, String>(); this.profileFetcher = new CdsProfileFetcher(); }
@Test public void testFetchApplicationIdFailureWithNon200StatusCode() throws InterruptedException, ExecutionException, ParseException, IOException { //setup MockHttpAsyncClientWrapper clientWrapper = new MockHttpAsyncClientWrapper(); clientWrapper.setAppId("AppId"); clientWrapper.setFailureOn(false); CdsProfileFetcher fetcher = new CdsProfileFetcher(); fetcher.setHttpClient(clientWrapper.getClient()); // the first time we try to fetch the profile, we might get a "pending" task status // since the profile fetcher uses asynchronous calls to retrieve the profile from CDS // this is mimic'ed with clientWrapper.setTaskAsPending(); clientWrapper.setTaskAsPending(); ProfileFetcherResult result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.PENDING, result.getStatus()); Assert.assertNull(result.getAppId()); // mimic task completion with 404 status code clientWrapper.setTaskAsComplete(); clientWrapper.setStatusCode(404); result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.FAILED, result.getStatus()); Assert.assertNull(result.getAppId()); }
@Test public void testFetchApplicationIdMultipleIkeys() throws InterruptedException, ExecutionException, ParseException, IOException { //setup MockHttpAsyncClientWrapper clientWrapper = new MockHttpAsyncClientWrapper(); clientWrapper.setAppId("AppId"); clientWrapper.setFailureOn(false); CdsProfileFetcher fetcher = new CdsProfileFetcher(); fetcher.setHttpClient(clientWrapper.getClient()); // the first time we try to fetch the profile, we should get a "pending" task status // since the profile fetcher uses asynchronous calls to retrieve the profile from CDS ProfileFetcherResult result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.PENDING, result.getStatus()); Assert.assertNull(result.getAppId()); // call for a second ikey, should also return "pending" result = fetcher.fetchAppProfile("ikey2"); Assert.assertEquals(ProfileFetcherResultTaskStatus.PENDING, result.getStatus()); Assert.assertNull(result.getAppId()); // mimic task completion clientWrapper.setTaskAsComplete(); result = fetcher.fetchAppProfile("ikey"); Assert.assertEquals(ProfileFetcherResultTaskStatus.COMPLETE, result.getStatus()); Assert.assertEquals("AppId", result.getAppId()); clientWrapper.setAppId("AppId2"); result = fetcher.fetchAppProfile("ikey2"); Assert.assertEquals(ProfileFetcherResultTaskStatus.COMPLETE, result.getStatus()); Assert.assertEquals("AppId2", result.getAppId()); }