@Test public void successFindsOneUpgradeService() throws Throwable { CountDownLatch latch = new CountDownLatch(1); UpgradeList[] out = new UpgradeList[1]; Operation get = new Operation().setCompletion((o, e) -> { out[0] = o.getBody(UpgradeList.class); latch.countDown(); }); ServiceDocumentQueryResult results = new ServiceDocumentQueryResult(); results.documentLinks = new ArrayList<>(Arrays.asList("/some/service", "/some/other/service")); doReturn(host).when(service).getHost(); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { invocation.getArgumentAt(2, Operation.class).setBody(results).complete(); return null; } }).when(host).queryServiceUris(eq(EnumSet.of(ServiceOption.FACTORY)), anyBoolean(), any(Operation.class)); service.handleGet(get); latch.await(); UpgradeList upgradeList = out[0]; assertThat(upgradeList.list.size(), is(1)); UpgradeInfo info = upgradeList.list.get(0); assertThat(info.destinationFactoryServicePath, is("/some/service")); assertThat(info.zookeeperServerSet, is("testService")); assertThat(info.destinationFactoryServicePath, is("/some/service")); assertThat(info.transformationServicePath, is("/transform")); }
@Override public void handleGet(Operation getOperation) { EnumSet<ServiceOption> options = EnumSet.of(ServiceOption.FACTORY); Operation op = new Operation(); op.setCompletion((o, e) -> { if (e != null) { getOperation.fail(e); return; } ServiceDocumentQueryResult result = o.getBody(ServiceDocumentQueryResult.class); Set<String> factories = new HashSet<>(result.documentLinks); List<UpgradeInfo> info = MigrationUtils.findAllUpgradeServices().stream() .filter(i -> factories.contains(i.destinationFactoryServicePath)) .map(i -> new UpgradeInfo(i)) .collect(Collectors.toList()); getOperation.setBody(Utils.toJson(false, true, new UpgradeList(info))).complete(); }); getHost().queryServiceUris(options, false, op); }
UpgradeInformationService extends StatelessService { @Override public void handleGet(Operation getOperation) { EnumSet<ServiceOption> options = EnumSet.of(ServiceOption.FACTORY); Operation op = new Operation(); op.setCompletion((o, e) -> { if (e != null) { getOperation.fail(e); return; } ServiceDocumentQueryResult result = o.getBody(ServiceDocumentQueryResult.class); Set<String> factories = new HashSet<>(result.documentLinks); List<UpgradeInfo> info = MigrationUtils.findAllUpgradeServices().stream() .filter(i -> factories.contains(i.destinationFactoryServicePath)) .map(i -> new UpgradeInfo(i)) .collect(Collectors.toList()); getOperation.setBody(Utils.toJson(false, true, new UpgradeList(info))).complete(); }); getHost().queryServiceUris(options, false, op); } }
UpgradeInformationService extends StatelessService { @Override public void handleGet(Operation getOperation) { EnumSet<ServiceOption> options = EnumSet.of(ServiceOption.FACTORY); Operation op = new Operation(); op.setCompletion((o, e) -> { if (e != null) { getOperation.fail(e); return; } ServiceDocumentQueryResult result = o.getBody(ServiceDocumentQueryResult.class); Set<String> factories = new HashSet<>(result.documentLinks); List<UpgradeInfo> info = MigrationUtils.findAllUpgradeServices().stream() .filter(i -> factories.contains(i.destinationFactoryServicePath)) .map(i -> new UpgradeInfo(i)) .collect(Collectors.toList()); getOperation.setBody(Utils.toJson(false, true, new UpgradeList(info))).complete(); }); getHost().queryServiceUris(options, false, op); }  }
UpgradeInformationService extends StatelessService { @Override public void handleGet(Operation getOperation) { EnumSet<ServiceOption> options = EnumSet.of(ServiceOption.FACTORY); Operation op = new Operation(); op.setCompletion((o, e) -> { if (e != null) { getOperation.fail(e); return; } ServiceDocumentQueryResult result = o.getBody(ServiceDocumentQueryResult.class); Set<String> factories = new HashSet<>(result.documentLinks); List<UpgradeInfo> info = MigrationUtils.findAllUpgradeServices().stream() .filter(i -> factories.contains(i.destinationFactoryServicePath)) .map(i -> new UpgradeInfo(i)) .collect(Collectors.toList()); getOperation.setBody(Utils.toJson(false, true, new UpgradeList(info))).complete(); }); getHost().queryServiceUris(options, false, op); }  @Override void handleGet(Operation getOperation); }
UpgradeInformationService extends StatelessService { @Override public void handleGet(Operation getOperation) { EnumSet<ServiceOption> options = EnumSet.of(ServiceOption.FACTORY); Operation op = new Operation(); op.setCompletion((o, e) -> { if (e != null) { getOperation.fail(e); return; } ServiceDocumentQueryResult result = o.getBody(ServiceDocumentQueryResult.class); Set<String> factories = new HashSet<>(result.documentLinks); List<UpgradeInfo> info = MigrationUtils.findAllUpgradeServices().stream() .filter(i -> factories.contains(i.destinationFactoryServicePath)) .map(i -> new UpgradeInfo(i)) .collect(Collectors.toList()); getOperation.setBody(Utils.toJson(false, true, new UpgradeList(info))).complete(); }); getHost().queryServiceUris(options, false, op); }  @Override void handleGet(Operation getOperation); static final String SELF_LINK; }