use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.
the class CacheResourceTest method testCORSAllOrigins.
@Test
public void testCORSAllOrigins() throws IOException {
RestServerHelper restServerHelper = null;
RestClient client = null;
try {
RestServerConfigurationBuilder restBuilder = new RestServerConfigurationBuilder();
restBuilder.cors().addNewRule().allowOrigins(new String[] { "*" });
restBuilder.host("localhost").port(0);
restServerHelper = RestServerHelper.defaultRestServer();
RestServerConfiguration build = restBuilder.build();
restServerHelper.withConfiguration(build).start("test");
client = restServerHelper.createClient();
RestResponse response = join(client.cache("default").get("test", singletonMap(ORIGIN.toString(), "http://host.example.com:5576")));
assertThat(response).containsAllHeaders("access-control-allow-origin");
} finally {
client.close();
if (restServerHelper != null)
restServerHelper.stop();
}
}
use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.
the class PipelineInitializationTest method testInitializationRules.
@Test
public void testInitializationRules() throws InterruptedException, ExecutionException {
int numTasks = 5;
ExecutorService executorService = Executors.newFixedThreadPool(numTasks);
CountDownLatch startLatch = new CountDownLatch(1);
List<Supplier<Integer>> suppliers = new ArrayList<>();
for (int i = 0; i < numTasks; i++) {
RestClient client = i % 2 == 0 ? client1 : client2;
suppliers.add(createTask(client, startLatch));
}
List<CompletableFuture<Integer>> results = suppliers.stream().map(s -> supplyAsync(s, executorService)).collect(Collectors.toList());
startLatch.countDown();
executorService.shutdown();
assertTrue(executorService.awaitTermination(5, TimeUnit.SECONDS));
for (CompletableFuture<Integer> result : results) {
assertFalse(result.isCompletedExceptionally());
assertEquals((int) result.get(), 200);
}
}
use of org.infinispan.client.rest.RestClient in project infinispan-quarkus by infinispan.
the class NativeCliIT method testCliBatch.
@Test
public void testCliBatch() throws Exception {
RestClient client = SERVER_TEST.rest().create();
RestCacheManagerClient cm = client.cacheManager("default");
RestResponse restResponse = sync(cm.healthStatus());
assertEquals(200, restResponse.getStatus());
assertEquals("HEALTHY", restResponse.getBody());
String cliPath = resource("ispn-cli");
String batchFile = resource("batch.file");
String hostname = SERVERS.getTestServer().getDriver().getServerAddress(0).getHostAddress() + ":11222";
String cliCmd = String.format("%s --connect %s --file=%s", cliPath, hostname, batchFile);
ProcessBuilder pb = new ProcessBuilder("bash", "-c", cliCmd);
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
Process p = pb.start();
StringBuilder sb = new StringBuilder();
new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()))) {
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}).start();
p.waitFor(5, TimeUnit.SECONDS);
assertEquals(0, p.exitValue());
String stderr = sb.toString();
if (!stderr.isEmpty()) {
System.err.println(stderr);
fail("Unexpected CLI output in stderr");
}
restResponse = sync(client.cache("mybatch").exists());
assertEquals(204, restResponse.getStatus());
}
use of org.infinispan.client.rest.RestClient in project infinispan-quarkus by infinispan.
the class RestCacheManagerResource method testCacheInfo.
@Test
public void testCacheInfo() throws Exception {
RestClient client = SERVER_TEST.rest().create();
String cacheName = "test";
RestResponse restResponse = sync(client.cache(cacheName).createWithTemplate("org.infinispan.LOCAL"));
assertEquals(200, restResponse.getStatus());
restResponse = sync(client.raw().get("/rest/v2/cache-managers/default/caches"));
assertEquals(200, restResponse.getStatus());
ArrayNode cacheArray = (ArrayNode) mapper.readTree(restResponse.getBody());
assertNotNull(cacheArray);
cacheArray.forEach(cache -> {
assertEquals("RUNNING", cache.get("status").asText());
assertEquals("HEALTHY", cache.get("health").asText());
if (cacheName.equals(cache.get("name").asText())) {
assertEquals("local-cache", cache.get("type").asText());
assertFalse(cache.get("simple_cache").asBoolean());
assertFalse(cache.get("transactional").asBoolean());
assertFalse(cache.get("persistent").asBoolean());
assertFalse(cache.get("bounded").asBoolean());
assertFalse(cache.get("indexed").asBoolean());
assertFalse(cache.get("secured").asBoolean());
assertFalse(cache.get("has_remote_backup").asBoolean());
}
});
}
use of org.infinispan.client.rest.RestClient in project infinispan by infinispan.
the class XSiteResourceTest method testGetStatusAllCaches.
@Test
public void testGetStatusAllCaches() {
RestClient restClient = clientPerSite.get(LON);
assertAllSitesOnline(restClient);
assertSuccessful(restClient.cache(CACHE_2).takeSiteOffline(NYC));
Json json = jsonResponseBody(restClient.cacheManager(CACHE_MANAGER).backupStatuses());
assertEquals(json.at(NYC).at("status").asString(), "mixed");
assertEquals(json.at(NYC).at("online").asJsonList().iterator().next().asString(), CACHE_1);
assertEquals(json.at(NYC).at("offline").asJsonList().iterator().next().asString(), CACHE_2);
json = jsonResponseBody(restClient.cacheManager(CACHE_MANAGER).backupStatus(NYC));
assertEquals(json.at("status").asString(), "mixed");
assertEquals(json.at("online").asJsonList().iterator().next().asString(), CACHE_1);
assertEquals(json.at("offline").asJsonList().iterator().next().asString(), CACHE_2);
assertSuccessful(restClient.cache(CACHE_2).bringSiteOnline(NYC));
assertAllSitesOnline(restClient);
// add a second node
TestSite site = site(LON);
EmbeddedCacheManager cm = site.addCacheManager(null, defaultGlobalConfigurationForSite(site.getSiteIndex()), defaultConfigurationForSite(site.getSiteIndex()), true);
site.waitForClusterToForm(CACHE_1);
site.waitForClusterToForm(CACHE_2);
TakeOfflineManager takeOfflineManager = TestingUtil.extractComponent(cm.getCache(CACHE_1), TakeOfflineManager.class);
takeOfflineManager.takeSiteOffline(NYC);
json = jsonResponseBody(restClient.cacheManager(CACHE_MANAGER).backupStatuses());
assertEquals(json.at(NYC).at("status").asString(), "mixed");
assertEquals(json.at(NYC).at("online").asJsonList().iterator().next().asString(), CACHE_2);
assertTrue(json.at(NYC).at("offline").asJsonList().isEmpty());
assertEquals(json.at(NYC).at("mixed").asJsonList().iterator().next().asString(), CACHE_1);
json = jsonResponseBody(restClient.cacheManager(CACHE_MANAGER).backupStatus(NYC));
assertEquals(json.at("status").asString(), "mixed");
assertEquals(json.at("online").asJsonList().iterator().next().asString(), CACHE_2);
assertTrue(json.at("offline").asJsonList().isEmpty());
assertEquals(json.at("mixed").asJsonList().iterator().next().asString(), CACHE_1);
takeOfflineManager.bringSiteOnline(NYC);
}
Aggregations