@SuppressWarnings("SameParameterValue") private void testAdminOp(String instanceName, String opName, int expectedStatus, Object expectedResult) throws IOException { testAdminOp(NamespaceId.DEFAULT.dataset(instanceName), opName, expectedStatus, expectedResult); }
private void testAdminOp(DatasetId datasetInstanceId, String opName, int expectedStatus, Object expectedResult) throws IOException { String path = String.format("/namespaces/%s/data/datasets/%s/admin/%s", datasetInstanceId.getNamespace(), datasetInstanceId.getEntityName(), opName); URL targetUrl = resolve(path); HttpResponse response = HttpRequests.execute(HttpRequest.post(targetUrl).build()); DatasetAdminOpResponse body = getResponse(response.getResponseBody()); Assert.assertEquals(expectedStatus, response.getResponseCode()); Assert.assertEquals(expectedResult, body.getResult()); }
@Test public void testUpdate() throws Exception { // check non-existence with 404 testAdminOp(bob, "exists", 404, null); // add instance, should automatically create an instance dsFramework.addInstance("table", bob, DatasetProperties.EMPTY); testAdminOp(bob, "exists", 200, true); dsFramework.updateInstance(bob, DatasetProperties.builder().add("dataset.table.ttl", "10000").build()); // check upgrade testAdminOp(bob, "upgrade", 200, null); // drop and check non-existence dsFramework.deleteInstance(bob); testAdminOp(bob, "exists", 404, null); }
@Test public void testRest() throws Exception { // check non-existence with 404 testAdminOp(bob, "exists", 404, null); // add instance, should automatically create an instance dsFramework.addInstance("table", bob, DatasetProperties.EMPTY); testAdminOp(bob, "exists", 200, true); testAdminOp("bob", "exists", 404, null); // check truncate final Table table = dsFramework.getDataset(bob, DatasetDefinition.NO_ARGUMENTS, null); Assert.assertNotNull(table); TransactionExecutor txExecutor = new DefaultTransactionExecutor(new InMemoryTxSystemClient(txManager), ImmutableList.of((TransactionAware) table)); // writing smth to table txExecutor.execute(() -> table.put(new Put("key1", "col1", "val1"))); // verify that we can read the data txExecutor.execute(() -> Assert.assertEquals("val1", table.get(new Get("key1", "col1")).getString("col1"))); testAdminOp(bob, "truncate", 200, null); // verify that data is no longer there txExecutor.execute(() -> Assert.assertTrue(table.get(new Get("key1", "col1")).isEmpty())); // check upgrade testAdminOp(bob, "upgrade", 200, null); // drop and check non-existence dsFramework.deleteInstance(bob); testAdminOp(bob, "exists", 404, null); }