private TestRequestSender getTestRequestSender() { ServiceHost peer = getHost(); return new TestRequestSender(peer); }
@Before public void setUp() { this.sender = new TestRequestSender(this.host); }
private TestRequestSender getTestRequestSender() { ServiceHost peer = getHost(); return new TestRequestSender(peer); }
@Before public void setUp() { this.sender = new TestRequestSender(this.host); }
private List<ExampleServiceState> getExampleServiceStates(ServiceHost host, List<String> servicePaths) { List<Operation> ops = servicePaths.stream() .map(path -> Operation.createGet(host, path)) .collect(toList()); TestRequestSender sender = new TestRequestSender(host); return sender.sendAndWait(ops, ExampleServiceState.class); }
private List<ExampleServiceState> getExampleServiceStates(ServiceHost host, List<String> servicePaths) { List<Operation> ops = servicePaths.stream() .map(path -> Operation.createGet(host, path)) .collect(toList()); TestRequestSender sender = new TestRequestSender(host); return sender.sendAndWait(ops, ExampleServiceState.class); }
@Before public void prepare() throws Throwable { // Wait for the example and example task factories to start because the host does not // wait for them since since they are not core services. Note that production code // should be asynchronous and not wait like this this.host.waitForServiceAvailable(ExampleService.FACTORY_LINK); this.host.waitForServiceAvailable(ExampleTaskService.FACTORY_LINK); this.sender = new TestRequestSender(this.host); }
@Before public void prepare() throws Throwable { // Wait for the example and example task factories to start because the host does not // wait for them since since they are not core services. Note that production code // should be asynchronous and not wait like this this.host.waitForServiceAvailable(ExampleService.FACTORY_LINK); this.host.waitForServiceAvailable(ExampleTaskService.FACTORY_LINK); this.sender = new TestRequestSender(this.host); }
/** * Abort a transaction */ public static boolean abort(VerificationHost host, String txid) throws Throwable { TestRequestSender sender = new TestRequestSender(host); try { Operation resultOp = sender.sendAndWait(createAbortOperation(host, txid)); if (resultOp.getStatusCode() == Operation.STATUS_CODE_OK) { return true; } } catch (Exception e) { host.log(Level.WARNING, "Exception aborting transaction: %s", e.getMessage()); } return false; }
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)); }
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 testAuthentication() throws Throwable { String headerVal = BasicAuthenticationUtils.constructBasicAuth(USER_JANE_EMAIL, USER_JANE_EMAIL); URI authServiceUri = UriUtils.buildUri(this.host, BasicAuthenticationService.SELF_LINK); TestRequestSender sender = new TestRequestSender(this.host); Operation returnOp = sender.sendAndWait((Operation .createPost(authServiceUri) .setBody(new Object()) .addRequestHeader(Operation.AUTHORIZATION_HEADER, headerVal))); assertTrue(returnOp.getStatusCode() == Operation.STATUS_CODE_OK); }
@Test public void testAuthentication() throws Throwable { String headerVal = BasicAuthenticationUtils.constructBasicAuth(USER_JANE_EMAIL, USER_JANE_EMAIL); URI authServiceUri = UriUtils.buildUri(this.host, BasicAuthenticationService.SELF_LINK); TestRequestSender sender = new TestRequestSender(this.host); Operation returnOp = sender.sendAndWait((Operation .createPost(authServiceUri) .setBody(new Object()) .addRequestHeader(Operation.AUTHORIZATION_HEADER, headerVal))); assertTrue(returnOp.getStatusCode() == Operation.STATUS_CODE_OK); }
private void testExternalAuthRedirectMultinode(ServiceHost host) { TestRequestSender sender = new TestRequestSender(host); // make a un-authenticated request on the host Operation requestOp = Operation.createGet(host.getUri()); Operation responseOp = sender.sendAndWait(requestOp); // check the redirect response assertEquals(Operation.STATUS_CODE_MOVED_TEMP, responseOp.getStatusCode()); // check the location header to redirect assertEquals("http://www.vmware.com", responseOp.getResponseHeader(Operation.LOCATION_HEADER)); }
private void testExternalAuthRedirectMultinode(ServiceHost host) { TestRequestSender sender = new TestRequestSender(host); // make a un-authenticated request on the host Operation requestOp = Operation.createGet(host.getUri()); Operation responseOp = sender.sendAndWait(requestOp); // check the redirect response assertEquals(Operation.STATUS_CODE_MOVED_TEMP, responseOp.getStatusCode()); // check the location header to redirect assertEquals("http://www.vmware.com", responseOp.getResponseHeader(Operation.LOCATION_HEADER)); }
private String createUsers(VerificationHost host, String userName, String email) throws Throwable { AuthorizationHelper authHelper = new AuthorizationHelper(host); String userServiceLink = authHelper.createUserService(host, email); authHelper.createRoles(host, email); AuthCredentialsServiceState authServiceState = new AuthCredentialsServiceState(); authServiceState.userEmail = email; authServiceState.privateKey = email; URI authUri = UriUtils.buildUri(host, AuthCredentialsService.FACTORY_LINK); TestRequestSender sender = new TestRequestSender(host); sender.sendAndWait(Operation.createPost(authUri).setBody(authServiceState)); return userServiceLink; }
private String createUsers(VerificationHost host, String userName, String email) throws Throwable { AuthorizationHelper authHelper = new AuthorizationHelper(host); String userServiceLink = authHelper.createUserService(host, email); authHelper.createRoles(host, email); AuthCredentialsServiceState authServiceState = new AuthCredentialsServiceState(); authServiceState.userEmail = email; authServiceState.privateKey = email; URI authUri = UriUtils.buildUri(host, AuthCredentialsService.FACTORY_LINK); TestRequestSender sender = new TestRequestSender(host); sender.sendAndWait(Operation.createPost(authUri).setBody(authServiceState)); return userServiceLink; }
@Test public void testAuthServiceFailure() throws Throwable { VerificationHost host = createAndStartHost(true, false, new FailQueueAuthenticationService()); TestRequestSender sender = new TestRequestSender(host); // make a un-authenticated request on the host and expect it to fail Operation requestOp = Operation.createGet(host.getUri()); FailureResponse response = sender.sendAndWaitFailure(requestOp); assertEquals(Operation.STATUS_CODE_FORBIDDEN, response.op.getStatusCode()); }
@Test public void testAuthServiceFailure() throws Throwable { VerificationHost host = createAndStartHost(true, false, new FailQueueAuthenticationService()); TestRequestSender sender = new TestRequestSender(host); // make a un-authenticated request on the host and expect it to fail Operation requestOp = Operation.createGet(host.getUri()); FailureResponse response = sender.sendAndWaitFailure(requestOp); assertEquals(Operation.STATUS_CODE_FORBIDDEN, response.op.getStatusCode()); }
private void testExternalAuthTokenRequestMultinode(ServiceHost host) { TestRequestSender sender = new TestRequestSender(host); // make a request to get the accessToken for the authentication service Operation requestOp = Operation.createGet(host, TestAuthenticationService.SELF_LINK) .forceRemote(); Operation responseOp = sender.sendAndWait(requestOp); String cookieHeader = responseOp.getResponseHeader(SET_COOKIE_HEADER); assertNotNull(cookieHeader); // assert the auth token cookie Cookie tokenCookie = ClientCookieDecoder.LAX.decode(cookieHeader); assertEquals(TestAuthenticationService.ACCESS_TOKEN, tokenCookie.value()); // assert the auth token header assertEquals(TestAuthenticationService.ACCESS_TOKEN, responseOp.getResponseHeader(Operation.REQUEST_AUTH_TOKEN_HEADER)); }