List of usage examples for java.lang Throwable toString
public String toString()
From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java
@Test public void testCreateAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); TenantsApi tenantsApi = new TenantsApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.createAsync("foo", new FutureCallback<Task>() { @Override//from w ww . j a v a2s . com public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); ; }
From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java
@Test public void testCreateAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); TenantsApi tenantsApi = new TenantsRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.createAsync("foo", new FutureCallback<Task>() { @Override/*from ww w . j a v a 2 s. c o m*/ public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); ; }
From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java
@Test public void testGetProjectsAsync() throws IOException, InterruptedException { Project project1 = new Project(); project1.setId("project1"); Project project2 = new Project(); project2.setId("project2"); final ResourceList<Project> projectResourceList = new ResourceList<>(Arrays.asList(project1, project2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(projectResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); TenantsApi tenantsApi = new TenantsApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.getProjectsAsync("foo", new FutureCallback<ResourceList<Project>>() { @Override//from ww w . j a va 2s . c om public void onSuccess(@Nullable ResourceList<Project> result) { assertEquals(result.getItems(), projectResourceList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java
@Test public void testGetProjectsAsync() throws IOException, InterruptedException { Project project1 = new Project(); project1.setId("project1"); Project project2 = new Project(); project2.setId("project2"); final ResourceList<Project> projectResourceList = new ResourceList<>(Arrays.asList(project1, project2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(projectResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); TenantsApi tenantsApi = new TenantsRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.getProjectsAsync("foo", new FutureCallback<ResourceList<Project>>() { @Override//from w ww.j a v a2s . c om public void onSuccess(@Nullable ResourceList<Project> result) { assertEquals(result.getItems(), projectResourceList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java
@Test public void testGetResourceTicketsAsync() throws IOException, InterruptedException { ResourceTicket resourceTicket1 = new ResourceTicket(); resourceTicket1.setId("resourceTicket1"); ResourceTicket resourceTicket2 = new ResourceTicket(); resourceTicket2.setId("resourceTicket2"); final ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>( Arrays.asList(resourceTicket1, resourceTicket2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(resourceTicketResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); TenantsApi tenantsApi = new TenantsApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.getResourceTicketsAsync("foo", new FutureCallback<ResourceList<ResourceTicket>>() { @Override//from www. j a v a 2s.c o m public void onSuccess(@Nullable ResourceList<ResourceTicket> result) { assertEquals(result.getItems(), resourceTicketResourceList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java
@Test public void testGetResourceTicketsAsync() throws IOException, InterruptedException { ResourceTicket resourceTicket1 = new ResourceTicket(); resourceTicket1.setId("resourceTicket1"); ResourceTicket resourceTicket2 = new ResourceTicket(); resourceTicket2.setId("resourceTicket2"); final ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>( Arrays.asList(resourceTicket1, resourceTicket2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(resourceTicketResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); TenantsApi tenantsApi = new TenantsRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.getResourceTicketsAsync("foo", new FutureCallback<ResourceList<ResourceTicket>>() { @Override//from w w w . ja va 2s . c o m public void onSuccess(@Nullable ResourceList<ResourceTicket> result) { assertEquals(result.getItems(), resourceTicketResourceList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java
@Test public void testListAsync() throws IOException, InterruptedException { Tenant tenant1 = new Tenant(); tenant1.setId("tenant1"); tenant1.setName("tenant1"); Tenant tenant2 = new Tenant(); tenant2.setId("tenant2"); tenant2.setName("tenant2"); final ResourceList<Tenant> tenantResourceList = new ResourceList<>(Arrays.asList(tenant1, tenant2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(tenantResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); TenantsApi tenantsApi = new TenantsApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.listByNameAsync("foo", new FutureCallback<ResourceList<Tenant>>() { @Override/*from ww w.j av a2s . c o m*/ public void onSuccess(@Nullable ResourceList<Tenant> result) { assertEquals(result.getItems(), tenantResourceList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.TenantsRestApiTest.java
@Test public void testListAsync() throws IOException, InterruptedException { Tenant tenant1 = new Tenant(); tenant1.setId("tenant1"); tenant1.setName("tenant1"); Tenant tenant2 = new Tenant(); tenant2.setId("tenant2"); tenant2.setName("tenant2"); final ResourceList<Tenant> tenantResourceList = new ResourceList<>(Arrays.asList(tenant1, tenant2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(tenantResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); TenantsApi tenantsApi = new TenantsRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.listByNameAsync("foo", new FutureCallback<ResourceList<Tenant>>() { @Override//www .ja v a2 s . co m public void onSuccess(@Nullable ResourceList<Tenant> result) { assertEquals(result.getItems(), tenantResourceList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.esminis.server.mariadb.server.MariaDbServerLauncher.java
void initializeDataDirectory(Context context, File binary, File root) throws IOException { File[] files = root.listFiles(); if (files != null && files.length > 0) { return;//from w w w.j a v a 2 s .c o m } synchronized (lock) { final List<String> environment = getEnvironment(); final List<String> command = createCommandInternal(context, binary, root); Collections.addAll(command, "--bootstrap", "--log-warnings=0", "--max_allowed_packet=8M", "--net_buffer_length=16K"); final File dataMysqlDirectory = new File(root, "mysql"); if (dataMysqlDirectory.isDirectory()) { return; } if (!dataMysqlDirectory.mkdirs()) { throw new IOException("Cannot create directory: " + dataMysqlDirectory.getAbsolutePath()); } final Process process = Runtime.getRuntime().exec(command.toArray(new String[command.size()]), environment.toArray(new String[environment.size()]), root); final Object[] finishedWithError = { null }; try { final OutputStream stream = process.getOutputStream(); Observable.create(new Observable.OnSubscribe<Void>() { @Override public void call(Subscriber<? super Void> subscriber) { final InputStream inputStream = process.getErrorStream(); String data = ""; for (;;) { synchronized (finishedWithError) { if (finishedWithError[0] != null) { break; } } try { int available = inputStream.available(); if (available > 0) { for (int i = 0; i < available; i++) { data += (char) inputStream.read(); } if (getFreeSpace(dataMysqlDirectory) < 1024L * 1024L || data.contains("No space left on device")) { synchronized (finishedWithError) { finishedWithError[0] = new IOException("No space left on device"); } process.destroy(); break; } } } catch (Throwable ignored) { } Thread.yield(); } subscriber.onCompleted(); } }).subscribeOn(Schedulers.newThread()).subscribe(); writeToStream(stream, "use mysql;\n"); writeToStream(stream, context, "sql/mysql_system_tables.sql"); writeToStream(stream, context, "sql/mysql_performance_tables.sql"); writeToStream(stream, context, "sql/mysql_system_tables_data.sql"); writeToStream(stream, context, "sql/add_root_from_any_host.sql"); writeToStream(stream, context, "sql/fill_help_tables.sql"); writeToStream(stream, "exit;\n"); process.waitFor(); } catch (Throwable e) { FileUtils.deleteDirectory(root); //noinspection ResultOfMethodCallIgnored root.mkdirs(); synchronized (finishedWithError) { if (finishedWithError[0] != null && finishedWithError[0] instanceof IOException) { throw (IOException) finishedWithError[0]; } else { throw new IOException( e.toString() + "\n\nLog:\n" + IOUtils.toString(process.getErrorStream())); } } } finally { synchronized (finishedWithError) { if (finishedWithError[0] == null) { finishedWithError[0] = true; } } } } }
From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java
@Test public void testGetProjectsAsyncForPagination() throws IOException, InterruptedException { Project project1 = new Project(); project1.setId("project1"); Project project2 = new Project(); project2.setId("project2"); Project project3 = new Project(); project3.setId("project3"); String nextPageLink = "nextPageLink"; ResourceList<Project> projectResourceList = new ResourceList<>(Arrays.asList(project1, project2), nextPageLink, null);//from w w w.j a v a 2s .co m ResourceList<Project> projectResourceListNextPage = new ResourceList<>(Arrays.asList(project3)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(projectResourceList); String serializedTaskNextPage = mapper.writeValueAsString(projectResourceListNextPage); setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK); TenantsApi tenantsApi = new TenantsApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.getProjectsAsync("foo", new FutureCallback<ResourceList<Project>>() { @Override public void onSuccess(@Nullable ResourceList<Project> result) { assertEquals(result.getItems().size(), projectResourceList.getItems().size() + projectResourceListNextPage.getItems().size()); assertTrue(result.getItems().containsAll(projectResourceList.getItems())); assertTrue(result.getItems().containsAll(projectResourceListNextPage.getItems())); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }