private void joinNodesAndVerifyConvergence() throws Throwable { TestNodeGroupManager manager = new TestNodeGroupManager(ServiceUriPaths.DEFAULT_NODE_GROUP_NAME); manager.addHosts(new ArrayList<>(this.hosts)); manager.joinNodeGroupAndWaitForConvergence(); }
/** * Logout from nodes in the node group. */ public static void logout(TestNodeGroupManager nodeGroup) { // to clear the cookie stored in service client in host, needs perform logout on all hosts nodeGroup.getAllHosts().forEach(AuthTestUtils::logout); }
/** * Attempt to login one of the host in the node group, and expect it to fail. */ public static void loginExpectFailure(TestNodeGroupManager nodeGroup, String username, String password) { ServiceHost peer = nodeGroup.getHost(); loginExpectFailure(peer, username, password); }
private List<NodeGroupState> getNodeGroupStates() { TestRequestSender sender = getTestRequestSender(); String nodeGroupPath = getNodeGroupPath(); List<Operation> nodeGroupOps = this.hosts.stream() .map(host -> UriUtils.buildUri(host.getUri(), nodeGroupPath)) .map(Operation::createGet) .collect(toList()); return sender.sendAndWait(nodeGroupOps, NodeGroupState.class); }
private void verifyCurrentQuorum(TestNodeGroupManager manager, int expectedQuorum) { ServiceHost node = manager.getHost(); TestRequestSender sender = new TestRequestSender(node); String nodeGroupPath = UriUtils.buildUriPath(ServiceUriPaths.NODE_GROUP_FACTORY, manager.getNodeGroupName()); Operation op = Operation.createGet(node, nodeGroupPath); NodeGroupState nodeGroupState = sender.sendAndWait(op, NodeGroupState.class); nodeGroupState.nodes.values().forEach( nodeState -> assertEquals("quorum on host=" + nodeState.id, expectedQuorum, nodeState.membershipQuorum)); }
@Test public void testExternalAuthenticationMultinode() throws Throwable { VerificationHost host1 = createAndStartHost(true, false, new TestAuthenticationService()); VerificationHost host2 = createAndStartHost(true, false, new TestAuthenticationService()); VerificationHost host3 = createAndStartHost(true, false, new TestAuthenticationService()); TestNodeGroupManager nodeGroup = new TestNodeGroupManager(); nodeGroup.addHost(host1); nodeGroup.addHost(host2); nodeGroup.addHost(host3); // perform lambda under system auth context AuthTestUtils.executeWithSystemAuthContext(nodeGroup, () -> { nodeGroup.joinNodeGroupAndWaitForConvergence(); // wait the service to be available in cluster nodeGroup.waitForFactoryServiceAvailable("/core/examples"); }); ServiceHost host = nodeGroup.getHost(); // test external auth redirect host1.log("Testing auth service redirect in multi-node"); testExternalAuthRedirectMultinode(host); host1.log("Auth service redirect in multi-node working as expected"); // test external auth token request host1.log("Testing auth service token request in multi-node"); testExternalAuthTokenRequestMultinode(host); host1.log("AuthenticationService token request is working in multi-node"); // test replication with external auth host1.log("Testing replication with external auth in multi-node"); testExternalAuthReplicationMultinode(host); host1.log("Replication with external auth in multi-node is working"); }
TestNodeGroupManager groupA = new TestNodeGroupManager("groupA") .addHost(host1) .addHost(host2) .addHost(host3) .createNodeGroup() // create groupA .joinNodeGroupAndWaitForConvergence(); // make them join groupA TestNodeGroupManager groupB = new TestNodeGroupManager("groupB") .addHost(host1) .addHost(host4) .createNodeGroup() // create groupB .joinNodeGroupAndWaitForConvergence(); // make them join groupB groupA.waitForFactoryServiceAvailable(ExampleService.FACTORY_LINK); groupB.waitForFactoryServiceAvailable(ExampleService.FACTORY_LINK); Set<String> expectedOwnerIds = groupA.getAllHosts().stream() .map(ServiceHost::getId) .collect(toSet()); groupA.updateQuorum(2, 1);
updateQuorum(quorum); String nodeGroupPath = getNodeGroupPath(); ServiceHost peer = getHost(); List<NodeGroupState> nodeGroupStates = getNodeGroupStates(); return nodeGroupStates.stream() .map(state -> state.membershipUpdateTimeMicros) }, "membershipUpdateTimeMicros has not updated."); getHost().log(Level.INFO, "membershipUpdateTimeMicros has updated"); waitForConvergence();
ServiceHost peer = getHost(); List<NodeGroupState> nodeGroupStates = getNodeGroupStates(); TestRequestSender sender = getTestRequestSender(); String nodeGroupPath = getNodeGroupPath(); Operation nodeGroupStateGetOp = Operation.createGet(host, nodeGroupPath); NodeGroupState nodeGroupState = sender.sendAndWait(nodeGroupStateGetOp, NodeGroupState.class);
TestNodeGroupManager manager = new TestNodeGroupManager(nodeGroupName); manager.addHosts(hosts); manager.setTimeout(timeout); manager.waitForConvergence(); } else { this.waitFor("Node group did not converge", () -> {
ServiceHost peer = getHost(); Operation selectPost = Operation.createPost(peer, nodeSelector).setBody(body); Operation selectResponse = getTestRequestSender().sendAndWait(selectPost); SelectOwnerResponse selectOwnerResponse = selectResponse .getBody(SelectOwnerResponse.class); .orElseThrow(() -> new RuntimeException("couldn't find owner node id")); ServiceHost ownerHost = getHost(ownerId) .orElseThrow(() -> new RuntimeException("couldn't find owner node")); Operation statsOp = Operation.createGet(factoryOwnerServiceStatsUri); ServiceStats stats = getTestRequestSender().sendAndWait(statsOp, ServiceStats.class); return isServiceStatAvailable(stats);
TestRequestSender sender = getTestRequestSender(); String nodeGroupPath = getNodeGroupPath(); UpdateQuorumRequest body = UpdateQuorumRequest.create(false); body.setMembershipQuorum(quorum); List<NodeGroupState> nodeGroupStates = getNodeGroupStates();
/** * Create a node group service instance on each of the attached hosts */ public TestNodeGroupManager createNodeGroup() { List<Operation> ops = this.hosts.stream() .map(host -> UriUtils.buildUri(host.getUri(), ServiceUriPaths.NODE_GROUP_FACTORY)) .map(uri -> { NodeGroupState body = new NodeGroupState(); body.documentSelfLink = this.nodeGroupName; return Operation.createPost(uri).setBodyNoCloning(body); }) .collect(toList()); // choose one peer and send all request in parallel then wait. getTestRequestSender().sendAndWait(ops); return this; }
@Test public void testExternalAuthenticationMultinode() throws Throwable { VerificationHost host1 = createAndStartHost(true, false, new TestAuthenticationService()); VerificationHost host2 = createAndStartHost(true, false, new TestAuthenticationService()); VerificationHost host3 = createAndStartHost(true, false, new TestAuthenticationService()); TestNodeGroupManager nodeGroup = new TestNodeGroupManager(); nodeGroup.addHost(host1); nodeGroup.addHost(host2); nodeGroup.addHost(host3); // perform lambda under system auth context AuthTestUtils.executeWithSystemAuthContext(nodeGroup, () -> { nodeGroup.joinNodeGroupAndWaitForConvergence(); // wait the service to be available in cluster nodeGroup.waitForFactoryServiceAvailable("/core/examples"); }); ServiceHost host = nodeGroup.getHost(); // test external auth redirect host1.log("Testing auth service redirect in multi-node"); testExternalAuthRedirectMultinode(host); host1.log("Auth service redirect in multi-node working as expected"); // test external auth token request host1.log("Testing auth service token request in multi-node"); testExternalAuthTokenRequestMultinode(host); host1.log("AuthenticationService token request is working in multi-node"); // test replication with external auth host1.log("Testing replication with external auth in multi-node"); testExternalAuthReplicationMultinode(host); host1.log("Replication with external auth in multi-node is working"); }
TestNodeGroupManager groupA = new TestNodeGroupManager("groupA") .addHost(host1) .addHost(host2) .addHost(host3) .createNodeGroup() // create groupA .joinNodeGroupAndWaitForConvergence(); // make them join groupA TestNodeGroupManager groupB = new TestNodeGroupManager("groupB") .addHost(host1) .addHost(host4) .createNodeGroup() // create groupB .joinNodeGroupAndWaitForConvergence(); // make them join groupB groupA.waitForFactoryServiceAvailable(ExampleService.FACTORY_LINK); groupB.waitForFactoryServiceAvailable(ExampleService.FACTORY_LINK); Set<String> expectedOwnerIds = groupA.getAllHosts().stream() .map(ServiceHost::getId) .collect(toSet()); groupA.updateQuorum(2, 1);
updateQuorum(quorum); String nodeGroupPath = getNodeGroupPath(); ServiceHost peer = getHost(); List<NodeGroupState> nodeGroupStates = getNodeGroupStates(); return nodeGroupStates.stream() .map(state -> state.membershipUpdateTimeMicros) }, "membershipUpdateTimeMicros has not updated."); getHost().log(Level.INFO, "membershipUpdateTimeMicros has updated"); waitForConvergence();
ServiceHost peer = getHost(); List<NodeGroupState> nodeGroupStates = getNodeGroupStates(); TestRequestSender sender = getTestRequestSender(); String nodeGroupPath = getNodeGroupPath(); Operation nodeGroupStateGetOp = Operation.createGet(host, nodeGroupPath); NodeGroupState nodeGroupState = sender.sendAndWait(nodeGroupStateGetOp, NodeGroupState.class);
TestNodeGroupManager manager = new TestNodeGroupManager(nodeGroupName); manager.addHosts(hosts); manager.setTimeout(timeout); manager.waitForConvergence(); } else { this.waitFor("Node group did not converge", () -> {
ServiceHost peer = getHost(); Operation selectPost = Operation.createPost(peer, nodeSelector).setBody(body); Operation selectResponse = getTestRequestSender().sendAndWait(selectPost); SelectOwnerResponse selectOwnerResponse = selectResponse .getBody(SelectOwnerResponse.class); .orElseThrow(() -> new RuntimeException("couldn't find owner node id")); ServiceHost ownerHost = getHost(ownerId) .orElseThrow(() -> new RuntimeException("couldn't find owner node")); Operation statsOp = Operation.createGet(factoryOwnerServiceStatsUri); ServiceStats stats = getTestRequestSender().sendAndWait(statsOp, ServiceStats.class); return isServiceStatAvailable(stats);
TestRequestSender sender = getTestRequestSender(); String nodeGroupPath = getNodeGroupPath(); UpdateQuorumRequest body = UpdateQuorumRequest.create(false); body.setMembershipQuorum(quorum); List<NodeGroupState> nodeGroupStates = getNodeGroupStates();