AbstractAnalyticsService implements AnalyticsService { protected static List<EndpointInfo> compressEndpointInfo(List<EndpointInfo> endpoints) { List<EndpointInfo> others = new ArrayList<EndpointInfo>(); EndpointPart rootPart = new EndpointPart(); for (int i = 0; i < endpoints.size(); i++) { EndpointInfo endpoint = endpoints.get(i); if (endpoint.getEndpoint() != null && endpoint.getEndpoint().length() > 1 && endpoint.getEndpoint().charAt(0) == '/') { String[] parts = endpoint.getEndpoint().split("/"); buildTree(rootPart, parts, 1, endpoint.getType()); } else { others.add(new EndpointInfo(endpoint)); } } List<EndpointInfo> info = null; if (endpoints.size() != others.size()) { rootPart.collapse(); info = extractEndpointInfo(rootPart); info.addAll(others); } else { info = others; } initEndpointInfo(info); return info; }  ConfigurationService getConfigurationService(); void setConfigurationService(ConfigurationService cs); @Override List<EndpointInfo> getUnboundEndpoints(String tenantId, long startTime, long endTime, boolean compress); @Override List<EndpointInfo> getBoundEndpoints(String tenantId, String transaction, long startTime,
                                    long endTime); @Override Collection<CommunicationSummaryStatistics> getCommunicationSummaryStatistics(String tenantId,
            Criteria criteria, boolean asTree);  }
@Test public void testCompressLeafNoOp() { List<EndpointInfo> uris = new ArrayList<EndpointInfo>(); for (int i = 0; i < 20; i++) { uris.add(new EndpointInfo().setEndpoint(EndpointUtil.encodeEndpoint("/hello/" + i, null)) .setType("http")); } List<EndpointInfo> result = AbstractAnalyticsService.compressEndpointInfo(uris); assertNotNull(result); assertEquals(1, result.size()); assertEquals("/hello/*", result.get(0).getEndpoint()); assertEquals("http", result.get(0).getType()); assertTrue(result.get(0).metaURI()); assertEquals("^/hello/.*$", result.get(0).getRegex()); assertEquals("/hello/{helloId}", result.get(0).getUriTemplate()); }
@Test public void testCompressLeafWithSingleOp() { List<EndpointInfo> uris = new ArrayList<EndpointInfo>(); for (int i = 0; i < 20; i++) { uris.add(new EndpointInfo().setEndpoint(EndpointUtil.encodeEndpoint("/hello/" + i, "op")) .setType("http")); } List<EndpointInfo> result = AbstractAnalyticsService.compressEndpointInfo(uris); assertNotNull(result); assertEquals(1, result.size()); assertEquals("/hello/*[op]", result.get(0).getEndpoint()); assertEquals("http", result.get(0).getType()); assertTrue(result.get(0).metaURI()); assertEquals("^/hello/.*\\[op\\]$", result.get(0).getRegex()); assertEquals("/hello/{helloId}", result.get(0).getUriTemplate()); }
@Test public void testCompressLeafWithMultiOp() { List<EndpointInfo> uris = new ArrayList<EndpointInfo>(); for (int i = 0; i < 30; i++) { uris.add(new EndpointInfo().setEndpoint(EndpointUtil.encodeEndpoint("/hello/" + i, "op" + (i % 2))) .setType("http")); } List<EndpointInfo> result = AbstractAnalyticsService.compressEndpointInfo(uris); assertNotNull(result); assertEquals(2, result.size()); EndpointInfo op0 = null; EndpointInfo op1 = null; for (EndpointInfo ei : result) { if (ei.getEndpoint().endsWith("[op0]")) { op0 = ei; } else if (ei.getEndpoint().endsWith("[op1]")) { op1 = ei; } else { fail("Unknown endpoint: " + ei); } } assertEquals("/hello/*[op0]", op0.getEndpoint()); assertEquals("/hello/*[op1]", op1.getEndpoint()); assertEquals("http", op0.getType()); assertEquals("http", op1.getType()); assertTrue(op0.metaURI()); assertTrue(op1.metaURI()); assertEquals("^/hello/.*\\[op0\\]$", op0.getRegex()); assertEquals("^/hello/.*\\[op1\\]$", op1.getRegex()); assertEquals("/hello/{helloId}", op0.getUriTemplate()); assertEquals("/hello/{helloId}", op1.getUriTemplate()); }
@Test public void testCompressPluralParameter() { List<EndpointInfo> uris = new ArrayList<EndpointInfo>(); for (int i = 0; i < 20; i++) { uris.add(new EndpointInfo().setEndpoint("/events/" + i).setType("http")); } List<EndpointInfo> result = AbstractAnalyticsService.compressEndpointInfo(uris); assertNotNull(result); assertEquals(1, result.size()); assertEquals("/events/*", result.get(0).getEndpoint()); assertEquals("http", result.get(0).getType()); assertTrue(result.get(0).metaURI()); assertEquals("^/events/.*$", result.get(0).getRegex()); assertEquals("/events/{eventId}", result.get(0).getUriTemplate()); }
@Test public void testCompressMidAndLeaf() { List<EndpointInfo> uris = new ArrayList<EndpointInfo>(); for (int i = 0; i < 400; i++) { uris.add(new EndpointInfo().setEndpoint("/hello/" + (i % 10) + "/mid/" + i / 10).setType("http")); } List<EndpointInfo> result = AbstractAnalyticsService.compressEndpointInfo(uris); assertNotNull(result); assertEquals(1, result.size()); assertEquals("/hellomid/.*$", result.get(0).getRegex()); assertEquals("/hello/{helloId}/mid/{midId}", result.get(0).getUriTemplate()); }
@Test public void testCompressTop() { List<EndpointInfo> uris = new ArrayList<EndpointInfo>(); for (int i = 0; i < 20; i++) { uris.add(new EndpointInfo().setEndpoint("/" + i + "/leaf").setType("http")); } List<EndpointInfo> result = AbstractAnalyticsService.compressEndpointInfo(uris); assertNotNull(result); assertEquals(1, result.size()); assertEquals("leaf$", result.get(0).getRegex()); assertEquals("/{param1}/leaf", result.get(0).getUriTemplate()); }
@Test public void testCompressConcurrentLevels() { List<EndpointInfo> uris = new ArrayList<EndpointInfo>(); for (int i = 0; i < 400; i++) { uris.add(new EndpointInfo().setEndpoint("/" + (i % 10) + "/" + i / 10).setType("http")); } List<EndpointInfo> result = AbstractAnalyticsService.compressEndpointInfo(uris); assertNotNull(result); assertEquals(1, result.size()); assertEquals(".*$", result.get(0).getRegex()); assertEquals("/{param1}/{param2}", result.get(0).getUriTemplate()); }
@Test public void testCompressDontObscureIntermediateLevel() { List<EndpointInfo> uris = new ArrayList<EndpointInfo>(); uris.add(new EndpointInfo().setEndpoint("/events").setType("http")); uris.add(new EndpointInfo().setEndpoint("/events/1").setType("http")); List<EndpointInfo> result = AbstractAnalyticsService.compressEndpointInfo(uris); assertNotNull(result); assertEquals(2, result.size()); assertEquals("/events", result.get(0).getEndpoint()); assertEquals("http", result.get(0).getType()); assertEquals("/events/1", result.get(1).getEndpoint()); assertEquals("http", result.get(1).getType()); assertFalse(result.get(0).metaURI()); assertFalse(result.get(1).metaURI()); }
@Test public void testCompressDontNonRest() { List<EndpointInfo> uris = new ArrayList<EndpointInfo>(); uris.add(new EndpointInfo().setEndpoint("/events").setType("http")); uris.add(new EndpointInfo().setEndpoint("[HornetQ]MyQueue").setType("mom")); uris.add(new EndpointInfo().setEndpoint("OtherURI-with-no-slash").setType("other")); List<EndpointInfo> result = AbstractAnalyticsService.compressEndpointInfo(uris); assertNotNull(result); assertEquals(3, result.size()); assertEquals("/events", result.get(0).getEndpoint()); assertEquals("http", result.get(0).getType()); assertEquals("[HornetQ]MyQueue", result.get(1).getEndpoint()); assertEquals("mom", result.get(1).getType()); assertEquals("OtherURI-with-no-slash", result.get(2).getEndpoint()); assertEquals("other", result.get(2).getType()); assertFalse(result.get(0).metaURI()); assertFalse(result.get(1).metaURI()); assertFalse(result.get(2).metaURI()); assertNotNull(result.get(0).getRegex()); assertNotNull(result.get(1).getRegex()); assertNotNull(result.get(2).getRegex()); }
@Test public void testCompressRootContext() { List<EndpointInfo> uris = new ArrayList<EndpointInfo>(); uris.add(new EndpointInfo().setEndpoint("/").setType("http")); List<EndpointInfo> result = AbstractAnalyticsService.compressEndpointInfo(uris); assertNotNull(result); assertEquals(1, result.size()); assertEquals("/", result.get(0).getEndpoint()); assertEquals("http", result.get(0).getType()); assertFalse(result.get(0).metaURI()); assertNotNull(result.get(0).getRegex()); }