System.out.println("Testing dynamic endpoint lookup...");
// Phase 1
System.out.println("Testing basic registry lookup functionality...");
MessageContext synCtx = TestUtils.createSynapseMessageContext("<empty/>", config);
Endpoint ep1 = synCtx.getEndpoint(KEY_DYNAMIC_ENDPOINT_1);
assertNotNull(ep1);
assertTrue(ep1.isInitialized());
assertEquals(1, registry.getHitCount());
assertEquals("http://test.url", ((AddressEndpoint) ep1).getDefinition().getAddress());
// Phase 2
System.out.println("Testing basic endpoint caching...");
synCtx = TestUtils.createSynapseMessageContext("<empty/>", config);
Endpoint ep2 = synCtx.getEndpoint(KEY_DYNAMIC_ENDPOINT_1);
assertNotNull(ep2);
assertEquals(1, registry.getHitCount());
assertTrue(ep1 == ep2);
// Phase 3
System.out.println("Testing advanced endpoint caching...");
synCtx = TestUtils.createSynapseMessageContext("<empty/>", config);
System.out.println("Waiting for the cache to expire...");
Thread.sleep(8500L);
Endpoint ep3 = synCtx.getEndpoint(KEY_DYNAMIC_ENDPOINT_1);
assertNotNull(ep3);
assertEquals(1, registry.getHitCount());
assertTrue(ep1 == ep3);
// Phase 4
System.out.println("Testing endpoint reloading...");
registry.updateResource(KEY_DYNAMIC_ENDPOINT_1, TestUtils.createOMElement(DYNAMIC_ENDPOINT_2));
System.out.println("Waiting for the cache to expire...");
Thread.sleep(8500L);
synCtx = TestUtils.createSynapseMessageContext("<empty/>", config);
Endpoint ep4 = synCtx.getEndpoint(KEY_DYNAMIC_ENDPOINT_1);
assertNotNull(ep4);
assertTrue(ep4.isInitialized());
assertEquals(2, registry.getHitCount());
assertEquals("http://test2.url", ((AddressEndpoint) ep4).getDefinition().getAddress());
assertTrue(ep1 != ep4);
assertTrue(!ep1.isInitialized());
// Phase 5
System.out.println("Testing for non-existing endpoints...");
synCtx = TestUtils.createSynapseMessageContext("<empty/>", config);
Endpoint ep5 = synCtx.getEndpoint("non-existing-endpoint");
assertNull(ep5);
System.out.println("Dynamic endpoint lookup tests were successful...");
}