mirror of https://github.com/apache/jclouds.git
Issue 695: Updated Predicate so it has a task client. Updated live test
This commit is contained in:
parent
890f377908
commit
8fc4d40045
|
@ -20,6 +20,7 @@ package org.jclouds.tmrk.enterprisecloud.predicates;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.features.TaskClient;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
@ -29,11 +30,16 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
*/
|
*/
|
||||||
public class TaskPredicates {
|
public class TaskPredicates {
|
||||||
|
|
||||||
public static Predicate<Task> completeOrSuccess() {
|
private TaskClient client;
|
||||||
|
|
||||||
|
public static Predicate<Task> completeOrSuccess(final TaskClient client) {
|
||||||
return new Predicate<Task>() {
|
return new Predicate<Task>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Task task) {
|
public boolean apply(Task task) {
|
||||||
checkNotNull(task,"task cannot be null");
|
checkNotNull(task,"task cannot be null");
|
||||||
|
if(client!=null) {
|
||||||
|
task = client.getTask(task.getURI());
|
||||||
|
}
|
||||||
switch(task.getStatus()) {
|
switch(task.getStatus()) {
|
||||||
case QUEUED:
|
case QUEUED:
|
||||||
case RUNNING:
|
case RUNNING:
|
||||||
|
|
|
@ -18,15 +18,18 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.tmrk.enterprisecloud.features;
|
package org.jclouds.tmrk.enterprisecloud.features;
|
||||||
|
|
||||||
|
import org.jclouds.predicates.RetryablePredicate;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
import org.jclouds.tmrk.enterprisecloud.domain.Task;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.service.Protocol;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetService;
|
||||||
|
import org.jclouds.tmrk.enterprisecloud.domain.service.internet.InternetServicePersistenceType;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.jclouds.tmrk.enterprisecloud.predicates.TaskPredicates.completeOrSuccess;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@code InternetServiceClient}
|
* Tests behavior of {@code InternetServiceClient}
|
||||||
|
@ -39,43 +42,48 @@ public class InternetServiceClientLiveTest extends BaseTerremarkEnterpriseCloudC
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
client = context.getApi().getInternetServiceClient();
|
client = context.getApi().getInternetServiceClient();
|
||||||
|
taskClient = context.getApi().getTaskClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
private InternetServiceClient client;
|
private InternetServiceClient client;
|
||||||
|
private TaskClient taskClient;
|
||||||
|
|
||||||
public void testGetInternetService() throws Exception {
|
public void testInternetServiceCalls() {
|
||||||
//TODO: The URI should come from the environment
|
InternetService service = InternetService.builder()
|
||||||
//TODO: Should create a new service edit it then delete it.
|
.name("live test")
|
||||||
//TODO: Need a retryable predicate to wait until the task is done.
|
.href(URI.create(""))
|
||||||
URI uri = URI.create("/cloudapi/ecloud/internetservices/797");
|
.protocol(Protocol.TCP)
|
||||||
InternetService internetService = client.getInternetService(uri);
|
.port(2020)
|
||||||
assertNotNull(internetService);
|
.enabled(true)
|
||||||
/*
|
.persistence(InternetServicePersistenceType.builder().persistenceType(InternetServicePersistenceType.PersistenceType.NONE).build())
|
||||||
final String originalName = internetService.getName();
|
.build();
|
||||||
final String newName = originalName+"edited";
|
|
||||||
boolean enable = !internetService.isEnabled();
|
|
||||||
|
|
||||||
// Change the name and enabled flag
|
// TODO: Fetch a public ip from the environment
|
||||||
testEditInternetService(internetService.getHref(),newName,enable);
|
// This has a method not allowed error - needs debugging.
|
||||||
internetService = client.getInternetService(uri);
|
URI uri = URI.create("/cloudapi/ecloud/publicips/3929");
|
||||||
assertEquals(internetService.getName(),newName);
|
InternetService internetService = client.createInternetService(uri, service);
|
||||||
assertEquals(internetService.isEnabled(),enable);
|
System.out.println("service:"+internetService);
|
||||||
|
|
||||||
// Change it back again
|
InternetService editServiceData = InternetService.builder().href(uri).name("testName").enabled(false).build();
|
||||||
enable = !internetService.isEnabled();
|
|
||||||
testEditInternetService(internetService.getHref(),originalName,enable);
|
Task editTask = client.editInternetService(editServiceData);
|
||||||
assertEquals(internetService.getName(),originalName);
|
System.out.println("Task:"+editTask);
|
||||||
assertEquals(internetService.isEnabled(),enable);
|
RetryablePredicate retryablePredicate = new RetryablePredicate(completeOrSuccess(taskClient), 1000*60);
|
||||||
*/
|
if (!retryablePredicate.apply(editTask)) {
|
||||||
|
fail("Did not manage to edit service:"+editTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
InternetService editedService = client.getInternetService(internetService.getHref());
|
||||||
|
assertEquals(editedService.getName(),"testName");
|
||||||
|
assertFalse(editedService.isEnabled());
|
||||||
|
|
||||||
|
Task removeTask = client.removeInternetService(internetService.getHref());
|
||||||
|
if (!retryablePredicate.apply(removeTask)) {
|
||||||
|
fail("Did not manage to remove service:"+removeTask);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetMissingInternetService() {
|
public void testGetMissingInternetService() {
|
||||||
assertNull(client.getInternetService(URI.create("/cloudapi/ecloud/internetservices/-1")));
|
assertNull(client.getInternetService(URI.create("/cloudapi/ecloud/internetservices/-1")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testEditInternetService(URI uri, String name, boolean enable) {
|
|
||||||
InternetService service = InternetService.builder().href(uri).name(name).enabled(enable).build();
|
|
||||||
Task task = client.editInternetService(service);
|
|
||||||
//TODO: Wait for task to complete.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,24 +50,24 @@ public class TaskPredicatesTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompleteOrSuccess() {
|
public void testCompleteOrSuccess() {
|
||||||
assertTrue(completeOrSuccess().apply(task.toBuilder().status(Task.Status.COMPLETE).build()));
|
assertTrue(completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.COMPLETE).build()));
|
||||||
assertTrue(completeOrSuccess().apply(task.toBuilder().status(Task.Status.SUCCESS).build()));
|
assertTrue(completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.SUCCESS).build()));
|
||||||
assertFalse(completeOrSuccess().apply(task.toBuilder().status(Task.Status.RUNNING).build()));
|
assertFalse(completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.RUNNING).build()));
|
||||||
assertFalse(completeOrSuccess().apply(task.toBuilder().status(Task.Status.QUEUED).build()));
|
assertFalse(completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.QUEUED).build()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testCompleteOrSuccessWhenNull() {
|
public void testCompleteOrSuccessWhenNull() {
|
||||||
TaskPredicates.completeOrSuccess().apply(null);
|
TaskPredicates.completeOrSuccess(null).apply(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = RuntimeException.class)
|
@Test(expectedExceptions = RuntimeException.class)
|
||||||
public void testCompleteOrSuccessWhenFailure() {
|
public void testCompleteOrSuccessWhenFailure() {
|
||||||
TaskPredicates.completeOrSuccess().apply(task.toBuilder().status(Task.Status.FAILED).build());
|
TaskPredicates.completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.FAILED).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = RuntimeException.class)
|
@Test(expectedExceptions = RuntimeException.class)
|
||||||
public void testCompleteOrSuccessWhenError() {
|
public void testCompleteOrSuccessWhenError() {
|
||||||
TaskPredicates.completeOrSuccess().apply(task.toBuilder().status(Task.Status.ERROR).build());
|
TaskPredicates.completeOrSuccess(null).apply(task.toBuilder().status(Task.Status.ERROR).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue