List of usage examples for org.apache.commons.collections4.map PassiveExpiringMap clear
@Override public void clear()
From source file:org.apache.ambari.view.utils.ambari.RemoteClusterTest.java
@Test public void testGetConfigurationValue() throws Exception { URLStreamProvider urlStreamProvider = createNiceMock(URLStreamProvider.class); final String desiredConfigsString = "{\"Clusters\": {\"desired_configs\": {\"test-site\": {\"tag\": \"TAG\"}}}}"; final String configurationString = "{\"items\": [{\"properties\": {\"test.property.name\": \"test property value\"}}]}"; final int[] desiredConfigPolls = { 0 }; final int[] testConfigPolls = { 0 }; expect(urlStreamProvider.readFrom(//from ww w .j ava 2s. co m eq(AMBARI_CLUSTER_REST_URL + "?fields=services/ServiceInfo,hosts,Clusters"), eq("GET"), (String) isNull(), (Map<String, String>) anyObject())).andAnswer(new IAnswer<InputStream>() { @Override public InputStream answer() throws Throwable { desiredConfigPolls[0] += 1; return new ByteArrayInputStream(desiredConfigsString.getBytes()); } }).anyTimes(); expect(urlStreamProvider.readFrom(eq(AMBARI_CLUSTER_REST_URL + "/configurations?(type=test-site&tag=TAG)"), eq("GET"), (String) isNull(), (Map<String, String>) anyObject())) .andAnswer(new IAnswer<InputStream>() { @Override public InputStream answer() throws Throwable { testConfigPolls[0] += 1; return new ByteArrayInputStream(configurationString.getBytes()); } }).anyTimes(); replay(urlStreamProvider); RemoteCluster cluster = new RemoteCluster(AMBARI_CLUSTER_REST_URL, urlStreamProvider); PassiveExpiringMap<String, JSONObject> cache = new PassiveExpiringMap<String, JSONObject>(10000L); cluster.configurationCache = cache; String value = cluster.getConfigurationValue("test-site", "test.property.name"); assertEquals(value, "test property value"); assertEquals(desiredConfigPolls[0], 1); assertEquals(testConfigPolls[0], 1); value = cluster.getConfigurationValue("test-site", "test.property.name"); assertEquals(value, "test property value"); assertEquals(desiredConfigPolls[0], 1); // cache hit assertEquals(testConfigPolls[0], 1); cache.clear(); value = cluster.getConfigurationValue("test-site", "test.property.name"); assertEquals(value, "test property value"); assertEquals(desiredConfigPolls[0], 2); assertEquals(testConfigPolls[0], 2); }