@Test public void testExactlyTwoDifferentExternalResourceNames() { Operation op1 = new Operation(); op1.type(RedisExternalResourceAnalyzer.TYPE); op1.putAnyNonEmpty("host", "127.0.0.1"); op1.put("port", 6379); op1.put("dbName", "dbName"); Operation op2 = new Operation(); op2.type(RedisExternalResourceAnalyzer.TYPE); op2.put("port", 6379); op2.put("dbName", "dbName2"); Operation dummyOp = new Operation(); SimpleFrameBuilder builder = new SimpleFrameBuilder(); builder.enter(new Operation().type(OperationType.HTTP)); builder.enter(op2); builder.exit(); builder.enter(dummyOp); builder.enter(op1); builder.exit(); builder.exit(); Frame frame = builder.exit(); Trace trace = Trace.newInstance(ApplicationName.valueOf("app"), TraceId.valueOf("0"), frame); List<ExternalResourceDescriptor> externalResourceDescriptors = (List<ExternalResourceDescriptor>) analyzer.locateExternalResourceName(trace); assertEquals(2, externalResourceDescriptors.size()); ExternalResourceDescriptor descriptor = externalResourceDescriptors.get(0); assertEquals(op2, descriptor.getFrame().getOperation()); assertEquals("dbName2", descriptor.getLabel()); assertEquals(ExternalResourceType.KVSTORE.name(), descriptor.getType()); assertEquals("Redis", descriptor.getVendor()); assertEquals(null, descriptor.getHost()); assertEquals(6379, descriptor.getPort()); String expectedHash = MD5NameGenerator.getName("dbName2" + null + 6379); assertEquals("redis:" + expectedHash, descriptor.getName()); assertEquals(Boolean.FALSE, Boolean.valueOf(descriptor.isIncoming())); descriptor = externalResourceDescriptors.get(1); assertEquals(op1, descriptor.getFrame().getOperation()); assertEquals("dbName", descriptor.getLabel()); assertEquals(ExternalResourceType.KVSTORE.name(), descriptor.getType()); assertEquals("Redis", descriptor.getVendor()); assertEquals("127.0.0.1", descriptor.getHost()); assertEquals(6379, descriptor.getPort()); expectedHash = MD5NameGenerator.getName("dbName127.0.0.1" + 6379); assertEquals("redis:" + expectedHash, descriptor.getName()); assertEquals(Boolean.FALSE, Boolean.valueOf(descriptor.isIncoming())); }
public List<ExternalResourceDescriptor> locateExternalResourceName(Trace trace, Collection<Frame> dbFrames) { if (ListUtil.size(dbFrames) <= 0) { return Collections.emptyList(); } List<ExternalResourceDescriptor> dbDescriptors = new ArrayList<ExternalResourceDescriptor>(dbFrames.size()); for (Frame dbFrame : dbFrames) { Operation op = dbFrame.getOperation(); String host = op.get("host", String.class); int port = op.getInt("port", (-1)); String color = colorManager.getColor(op); String dbName = op.get("dbName", String.class); String redisHash = MD5NameGenerator.getName(dbName + host + port); dbDescriptors.add(new ExternalResourceDescriptor(dbFrame, "redis:" + redisHash, dbName, ExternalResourceType.KVSTORE.name(), "Redis", host, port, color, false)); } return dbDescriptors; }
RedisExternalResourceAnalyzer extends AbstractExternalResourceAnalyzer { public List<ExternalResourceDescriptor> locateExternalResourceName(Trace trace, Collection<Frame> dbFrames) { if (ListUtil.size(dbFrames) <= 0) { return Collections.emptyList(); } List<ExternalResourceDescriptor> dbDescriptors = new ArrayList<ExternalResourceDescriptor>(dbFrames.size()); for (Frame dbFrame : dbFrames) { Operation op = dbFrame.getOperation(); String host = op.get("host", String.class); int port = op.getInt("port", (-1)); String color = colorManager.getColor(op); String dbName = op.get("dbName", String.class); String redisHash = MD5NameGenerator.getName(dbName + host + port); dbDescriptors.add(new ExternalResourceDescriptor(dbFrame, "redis:" + redisHash, dbName, ExternalResourceType.KVSTORE.name(), "Redis", host, port, color, false)); } return dbDescriptors; } }
RedisExternalResourceAnalyzer extends AbstractExternalResourceAnalyzer { public List<ExternalResourceDescriptor> locateExternalResourceName(Trace trace, Collection<Frame> dbFrames) { if (ListUtil.size(dbFrames) <= 0) { return Collections.emptyList(); } List<ExternalResourceDescriptor> dbDescriptors = new ArrayList<ExternalResourceDescriptor>(dbFrames.size()); for (Frame dbFrame : dbFrames) { Operation op = dbFrame.getOperation(); String host = op.get("host", String.class); int port = op.getInt("port", (-1)); String color = colorManager.getColor(op); String dbName = op.get("dbName", String.class); String redisHash = MD5NameGenerator.getName(dbName + host + port); dbDescriptors.add(new ExternalResourceDescriptor(dbFrame, "redis:" + redisHash, dbName, ExternalResourceType.KVSTORE.name(), "Redis", host, port, color, false)); } return dbDescriptors; } private  RedisExternalResourceAnalyzer(); }
RedisExternalResourceAnalyzer extends AbstractExternalResourceAnalyzer { public List<ExternalResourceDescriptor> locateExternalResourceName(Trace trace, Collection<Frame> dbFrames) { if (ListUtil.size(dbFrames) <= 0) { return Collections.emptyList(); } List<ExternalResourceDescriptor> dbDescriptors = new ArrayList<ExternalResourceDescriptor>(dbFrames.size()); for (Frame dbFrame : dbFrames) { Operation op = dbFrame.getOperation(); String host = op.get("host", String.class); int port = op.getInt("port", (-1)); String color = colorManager.getColor(op); String dbName = op.get("dbName", String.class); String redisHash = MD5NameGenerator.getName(dbName + host + port); dbDescriptors.add(new ExternalResourceDescriptor(dbFrame, "redis:" + redisHash, dbName, ExternalResourceType.KVSTORE.name(), "Redis", host, port, color, false)); } return dbDescriptors; } private  RedisExternalResourceAnalyzer(); static final RedisExternalResourceAnalyzer getInstance(); List<ExternalResourceDescriptor> locateExternalResourceName(Trace trace, Collection<Frame> dbFrames); }
RedisExternalResourceAnalyzer extends AbstractExternalResourceAnalyzer { public List<ExternalResourceDescriptor> locateExternalResourceName(Trace trace, Collection<Frame> dbFrames) { if (ListUtil.size(dbFrames) <= 0) { return Collections.emptyList(); } List<ExternalResourceDescriptor> dbDescriptors = new ArrayList<ExternalResourceDescriptor>(dbFrames.size()); for (Frame dbFrame : dbFrames) { Operation op = dbFrame.getOperation(); String host = op.get("host", String.class); int port = op.getInt("port", (-1)); String color = colorManager.getColor(op); String dbName = op.get("dbName", String.class); String redisHash = MD5NameGenerator.getName(dbName + host + port); dbDescriptors.add(new ExternalResourceDescriptor(dbFrame, "redis:" + redisHash, dbName, ExternalResourceType.KVSTORE.name(), "Redis", host, port, color, false)); } return dbDescriptors; } private  RedisExternalResourceAnalyzer(); static final RedisExternalResourceAnalyzer getInstance(); List<ExternalResourceDescriptor> locateExternalResourceName(Trace trace, Collection<Frame> dbFrames); static final OperationType TYPE; }