From cfe31695c08e4f31d386284f1e5b6a4f47a0a6ef Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Wed, 26 Oct 2011 17:15:58 -0400 Subject: [PATCH 01/10] [issue 737] Modified apis/filesystem tests to skip tests that are known not to work on Windows --- .../FilesystemAsyncBlobStoreTest.java | 24 +++++++++++++++---- .../FilesystemStorageStrategyImplTest.java | 10 +++++++- .../jclouds/filesystem/utils/TestUtils.java | 6 +++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java index 60b38f649d..8056edf97b 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/FilesystemAsyncBlobStoreTest.java @@ -62,6 +62,7 @@ import org.jclouds.io.payloads.PhantomPayload; import org.jclouds.io.payloads.StringPayload; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import com.google.inject.CreationException; @@ -83,7 +84,6 @@ public class FilesystemAsyncBlobStoreTest { static { System.setProperty(LOGGING_CONFIG_KEY, LOGGING_CONFIG_VALUE); - } private BlobStoreContext context = null; @@ -119,6 +119,12 @@ public class FilesystemAsyncBlobStoreTest { } } + @DataProvider + public Object[][] ignoreOnWindows() { + return (TestUtils.isWindowsOs() ? TestUtils.NO_INVOCATIONS + : TestUtils.SINGLE_NO_ARG_INVOCATION); + } + /** * Checks if context parameters are managed in the correct way */ @@ -399,6 +405,7 @@ public class FilesystemAsyncBlobStoreTest { /** * Test of removeBlob method, with only one blob with a complex path as key */ + @Test(dataProvider = "ignoreOnWindows", description = "see http://code.google.com/p/jclouds/issues/detail?id=737") public void testRemoveBlob_ComplexBlobKey() throws IOException { final String BLOB_KEY = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null); boolean result; @@ -429,6 +436,7 @@ public class FilesystemAsyncBlobStoreTest { * when first blob is removed, not all of its key's path is removed, because * it is shared with the second blob's key */ + @Test(dataProvider = "ignoreOnWindows", description = "see http://code.google.com/p/jclouds/issues/detail?id=737") public void testRemoveBlob_TwoComplexBlobKeys() throws IOException { final String BLOB_KEY1 = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null); final String BLOB_KEY2 = TestUtils.createRandomBlobKey("aa/bb/ee/ff/", null); @@ -702,6 +710,7 @@ public class FilesystemAsyncBlobStoreTest { TestUtils.directoryExists(TARGET_CONTAINER_NAME2, false); } + @Test(dataProvider = "ignoreOnWindows", description = "see http://code.google.com/p/jclouds/issues/detail?id=737") public void testInvalidContainerName() { try { blobStore.createContainerInLocation(null, "file/system"); @@ -716,23 +725,28 @@ public class FilesystemAsyncBlobStoreTest { } public void testRanges() throws IOException { + /* + * Using CONTAINER_NAME here breaks tests on Windows because the container + * can't be deleted. See http://code.google.com/p/jclouds/issues/detail?id=737 + */ + final String containerName = "containerWithRanges"; String payload = "abcdefgh"; Blob blob = blobStore.blobBuilder("test").payload(new StringPayload(payload)).build(); - blobStore.putBlob(CONTAINER_NAME, blob); + blobStore.putBlob(containerName, blob); GetOptions getOptionsRangeStartAt = new GetOptions(); getOptionsRangeStartAt.startAt(1); - Blob blobRangeStartAt = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt); + Blob blobRangeStartAt = blobStore.getBlob(containerName, blob.getMetadata().getName(), getOptionsRangeStartAt); Assert.assertEquals("bcdefgh", IOUtils.toString(blobRangeStartAt.getPayload().getInput())); GetOptions getOptionsRangeTail = new GetOptions(); getOptionsRangeTail.tail(3); - Blob blobRangeTail = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail); + Blob blobRangeTail = blobStore.getBlob(containerName, blob.getMetadata().getName(), getOptionsRangeTail); Assert.assertEquals("fgh", IOUtils.toString(blobRangeTail.getPayload().getInput())); GetOptions getOptionsFragment = new GetOptions(); getOptionsFragment.range(4, 6); - Blob blobFragment = blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment); + Blob blobFragment = blobStore.getBlob(containerName, blob.getMetadata().getName(), getOptionsFragment); Assert.assertEquals("efg", IOUtils.toString(blobFragment.getPayload().getInput())); } diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java index 5a40c807f2..599d789075 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java @@ -48,6 +48,7 @@ import org.jclouds.filesystem.utils.TestUtils; import org.jclouds.io.payloads.FilePayload; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; /** @@ -92,6 +93,12 @@ public class FilesystemStorageStrategyImplTest { TestUtils.cleanDirectoryContent(TestUtils.TARGET_BASE_DIR); } + @DataProvider + public Object[][] ignoreOnWindows() { + return (TestUtils.isWindowsOs() ? TestUtils.NO_INVOCATIONS + : TestUtils.SINGLE_NO_ARG_INVOCATION); + } + public void testCreateDirectory() { storageStrategy.createDirectory(CONTAINER_NAME, null); TestUtils.directoryExists(TARGET_CONTAINER_NAME, true); @@ -114,10 +121,11 @@ public class FilesystemStorageStrategyImplTest { storageStrategy.createDirectory(CONTAINER_NAME, null); } + @Test(dataProvider = "ignoreOnWindows", description = "see http://code.google.com/p/jclouds/issues/detail?id=737") public void testCreateDirectory_WrongDirectoryName() { try { storageStrategy.createDirectory(CONTAINER_NAME, "$%&!'`\\/"); - fail("No exception throwed"); + fail("No exception thrown"); } catch (Exception e) { } } diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java index 5388858c2a..d9ea6c05ff 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/utils/TestUtils.java @@ -48,6 +48,12 @@ public class TestUtils { public static final String TARGET_BASE_DIR = "." + File.separator + "target" + File.separator + "basedir" + File.separator; + public static final Object[][] NO_INVOCATIONS = new Object[0][0]; + public static final Object[][] SINGLE_NO_ARG_INVOCATION = new Object[][] { new Object[0] }; + + public static boolean isWindowsOs() { + return System.getProperty("os.name", "").toLowerCase().contains("windows"); + } /** * Generate a random blob key simple name (with no path in the key) From 0e06eedcdbb4c78b0236b5685eb7de2e4172d7d5 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Fri, 3 Jun 2011 20:31:38 +0200 Subject: [PATCH 02/10] Ignoring the tests that cause issue 402 on Windows for the 1.0.0 release --- .../jclouds/vcloud/VCloudAsyncClientTest.java | 9 +++++ .../vcloud/features/VmAsyncClientTest.java | 9 +++++ .../org/jclouds/vcloud/utils/TestUtils.java | 34 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 apis/vcloud/src/test/java/org/jclouds/vcloud/utils/TestUtils.java diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index d45a40752e..3c4f0796c9 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -43,6 +43,7 @@ import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest; import org.jclouds.vcloud.options.CaptureVAppOptions; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import org.jclouds.vcloud.utils.TestUtils; import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.CatalogItemHandler; import org.jclouds.vcloud.xml.OrgHandler; @@ -55,6 +56,7 @@ import org.jclouds.vcloud.xml.VAppTemplateHandler; import org.jclouds.vcloud.xml.VDCHandler; import org.jclouds.vcloud.xml.VmHandler; import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import com.google.inject.TypeLiteral; @@ -116,6 +118,7 @@ public class VCloudAsyncClientTest extends BaseVCloudAsyncClientTest checkFilters(request); } + @Test(dataProvider = "ignoreOnWindows", description = "see http://code.google.com/p/jclouds/issues/detail?id=402") public void testUpdateGuestConfiguration() throws SecurityException, NoSuchMethodException, IOException { Method method = VmAsyncClient.class.getMethod("updateGuestCustomizationOfVm", GuestCustomizationSection.class, URI.class); @@ -316,4 +319,10 @@ public class VmAsyncClientTest extends BaseVCloudAsyncClientTest checkFilters(request); } + @DataProvider + public Object[][] ignoreOnWindows() { + return (TestUtils.isWindowsOs() ? TestUtils.NO_INVOCATIONS + : TestUtils.SINGLE_NO_ARG_INVOCATION); + } + } diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/utils/TestUtils.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/utils/TestUtils.java new file mode 100644 index 0000000000..1831852f10 --- /dev/null +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/utils/TestUtils.java @@ -0,0 +1,34 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.utils; + + +/** + * Utility class for test + * + * @author Andrew Phillips + */ +public class TestUtils { + public static final Object[][] NO_INVOCATIONS = new Object[0][0]; + public static final Object[][] SINGLE_NO_ARG_INVOCATION = new Object[][] { new Object[0] }; + + public static boolean isWindowsOs() { + return System.getProperty("os.name", "").toLowerCase().contains("windows"); + } +} From 39dbc592b5bbc0d220bbeb5b53f0d0abeb12e69a Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Wed, 26 Oct 2011 21:25:34 -0400 Subject: [PATCH 03/10] Using OS-dependent file separators in asserts (instead of assuming UNIX '/') --- .../callables/InitScriptConfigurationForTasksTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compute/src/test/java/org/jclouds/compute/callables/InitScriptConfigurationForTasksTest.java b/compute/src/test/java/org/jclouds/compute/callables/InitScriptConfigurationForTasksTest.java index 1e55115dc9..b70409cafd 100644 --- a/compute/src/test/java/org/jclouds/compute/callables/InitScriptConfigurationForTasksTest.java +++ b/compute/src/test/java/org/jclouds/compute/callables/InitScriptConfigurationForTasksTest.java @@ -18,8 +18,11 @@ */ package org.jclouds.compute.callables; +import static java.lang.String.format; import static org.testng.Assert.assertEquals; +import java.io.File; + import org.testng.annotations.Test; import com.google.inject.AbstractModule; @@ -42,7 +45,7 @@ public class InitScriptConfigurationForTasksTest { public void testPatternUpdatesBasedir() { InitScriptConfigurationForTasks config = InitScriptConfigurationForTasks.create(); config.initScriptPattern("/var/foo-init-%s"); - assertEquals(config.getBasedir(), "/var"); + assertEquals(config.getBasedir(), format("%svar", File.separator)); assertEquals(config.getInitScriptPattern(), "/var/foo-init-%s"); } @@ -57,7 +60,7 @@ public class InitScriptConfigurationForTasksTest { }).getInstance(InitScriptConfigurationForTasks.class); config.initScriptPattern("/var/foo-init-%s"); - assertEquals(config.getBasedir(), "/var"); + assertEquals(config.getBasedir(), format("%svar", File.separator)); assertEquals(config.getInitScriptPattern(), "/var/foo-init-%s"); } From 893171ba5950f89964a9e127515fc7e00ca575b5 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Thu, 27 Oct 2011 15:40:55 -0400 Subject: [PATCH 04/10] Fixed licence header (thanks, Andrei!) --- .../org/jclouds/vcloud/utils/TestUtils.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/utils/TestUtils.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/utils/TestUtils.java index 1831852f10..2908ee028e 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/utils/TestUtils.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/utils/TestUtils.java @@ -1,20 +1,20 @@ /** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * Copyright (C) 2011 Cloud Conscious, LLC. + * http://www.apache.org/licenses/LICENSE-2.0 * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.jclouds.vcloud.utils; From ab882bf0352d8c2ff1f8707b249d8d5e0d5bc6e7 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Sat, 29 Oct 2011 11:56:42 -0400 Subject: [PATCH 05/10] Merge branch 'ignore-failed-windows-tests', remote-tracking branch 'origin' From 8b3010b5879b4e49a2ac2df5544579f8b5fff724 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 29 Oct 2011 22:30:57 +0200 Subject: [PATCH 06/10] fixed NPE and backfilled test --- .../functions/ParseFirstJsonValueNamed.java | 13 +- .../ParseFirstJsonValueNamedTest.java | 138 ++++++++++++++++++ 2 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 core/src/test/java/org/jclouds/http/functions/ParseFirstJsonValueNamedTest.java diff --git a/core/src/main/java/org/jclouds/http/functions/ParseFirstJsonValueNamed.java b/core/src/main/java/org/jclouds/http/functions/ParseFirstJsonValueNamed.java index ccd058a898..52d98885a1 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseFirstJsonValueNamed.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseFirstJsonValueNamed.java @@ -27,8 +27,11 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +import javax.annotation.Resource; + import org.jclouds.http.HttpResponse; import org.jclouds.json.internal.GsonWrapper; +import org.jclouds.logging.Logger; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; @@ -44,6 +47,9 @@ import com.google.inject.TypeLiteral; */ public class ParseFirstJsonValueNamed implements Function { + @Resource + protected Logger logger = Logger.NULL; + private final GsonWrapper json; private final TypeLiteral type; private final String name; @@ -68,8 +74,11 @@ public class ParseFirstJsonValueNamed implements Function { for (; token != JsonToken.END_DOCUMENT && nnn(this.name, reader, token, name); token = skipAndPeek(token, reader)) ; - if (name.get().equals(this.name)) { - return json.delegate().fromJson(reader, type.getType()); + if (name.get() == null) { + logger.trace("did not object named %s in json from response %s", this.name, arg0); + return nothing(); + } else if (name.get().equals(this.name)) { + return json.delegate(). fromJson(reader, type.getType()); } else { return nothing(); } diff --git a/core/src/test/java/org/jclouds/http/functions/ParseFirstJsonValueNamedTest.java b/core/src/test/java/org/jclouds/http/functions/ParseFirstJsonValueNamedTest.java new file mode 100644 index 0000000000..0f043bc8b9 --- /dev/null +++ b/core/src/test/java/org/jclouds/http/functions/ParseFirstJsonValueNamedTest.java @@ -0,0 +1,138 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.http.functions; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payloads; +import org.jclouds.json.config.GsonModule; +import org.jclouds.json.internal.GsonWrapper; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +@Test(testName = "ParseFirstJsonValueNamedTest") +public class ParseFirstJsonValueNamedTest { + + GsonWrapper json = Guice.createInjector(new GsonModule()).getInstance(GsonWrapper.class); + + static class Event { + private String name; + private String source; + + private Event(String name, String source) { + this.name = name; + this.source = source; + } + + @Override + public String toString() { + return String.format("(name=%s, source=%s)", name, source); + } + } + + public void testParseNestedElements() throws IOException { + String nested = "{ \"count\":1 ,\"event\" : [ {name:'GREETINGS',source:'guest'} ] }"; + HttpResponse response = HttpResponse.builder().statusCode(200).message("goodie") + .payload(Payloads.newPayload(nested)).build(); + + List val = new ParseFirstJsonValueNamed>(json, new TypeLiteral>() { + }, "event").apply(response); + assertEquals(val.toString(), "[(name=GREETINGS, source=guest)]"); + } + + public void testParseNestedElementsWhenNotFoundIsEmpty() throws IOException { + String nested = "{ \"count\":1 ,\"evant\" : [ {name:'GREETINGS',source:'guest'} ] }"; + HttpResponse response = HttpResponse.builder().statusCode(200).message("goodie") + .payload(Payloads.newPayload(nested)).build(); + + List val = new ParseFirstJsonValueNamed>(json, new TypeLiteral>() { + }, "event").apply(response); + assertEquals(val.toString(), "[]"); + } + + public void testParseNestedElementsButNothing() throws IOException { + String nested = "{ \"count\":1 ,\"event\" : [ ] }"; + HttpResponse response = HttpResponse.builder().statusCode(200).message("goodie") + .payload(Payloads.newPayload(nested)).build(); + + List val = new ParseFirstJsonValueNamed>(json, new TypeLiteral>() { + }, "event").apply(response); + assertEquals(val.toString(), "[]"); + } + + public void testParseNestedFurtherElements() throws IOException { + String nestedFurther = "{ \"listaccountsresponse\" : { \"count\":1 ,\"event\" : [ {name:'GREETINGS',source:'guest'} ] } }"; + HttpResponse response = HttpResponse.builder().statusCode(200).message("goodie") + .payload(Payloads.newPayload(nestedFurther)).build(); + + List val = new ParseFirstJsonValueNamed>(json, new TypeLiteral>() { + }, "event").apply(response); + assertEquals(val.toString(), "[(name=GREETINGS, source=guest)]"); + } + + public void testParseNestedFurtherElementsButNothing() throws IOException { + String nestedFurther = "{ \"listaccountsresponse\" : { \"count\":1 ,\"event\" : [ ] } }"; + HttpResponse response = HttpResponse.builder().statusCode(200).message("goodie") + .payload(Payloads.newPayload(nestedFurther)).build(); + + List val = new ParseFirstJsonValueNamed>(json, new TypeLiteral>() { + }, "event").apply(response); + assertEquals(val.toString(), "[]"); + } + + public void testParseNoPayloadEmptyList() throws IOException { + HttpResponse response = HttpResponse.builder().statusCode(200).message("goodie").build(); + + List val = new ParseFirstJsonValueNamed>(json, new TypeLiteral>() { + }, "event").apply(response); + assertEquals(val, ImmutableList. of()); + } + + public void testParseNoPayloadEmptyMap() throws IOException { + HttpResponse response = HttpResponse.builder().statusCode(200).message("goodie").build(); + + Map val = new ParseFirstJsonValueNamed>(json, + new TypeLiteral>() { + }, "event").apply(response); + assertEquals(val, ImmutableMap. of()); + } + + public void testParseNoPayloadEmptySet() throws IOException { + HttpResponse response = HttpResponse.builder().statusCode(200).message("goodie").build(); + + Set val = new ParseFirstJsonValueNamed>(json, new TypeLiteral>() { + }, "event").apply(response); + assertEquals(val, ImmutableSet. of()); + } +} From 3404850aba6b8d91df12538586dfc4992e90a315 Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Sat, 29 Oct 2011 21:48:55 +0200 Subject: [PATCH 07/10] Small fix for running live tests from clean slate. Still stuff to do to get it running more than once... --- .../LaunchMachineIfNotAlreadyRunning.java | 27 ++++++++++--------- .../LaunchMachineIfNotAlreadyRunningTest.java | 9 +++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java index 8c7059f9c4..71ff12bc54 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java @@ -29,10 +29,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.virtualbox.domain.ErrorCode; import org.jclouds.virtualbox.domain.ExecutionType; -import org.virtualbox_4_1.IMachine; -import org.virtualbox_4_1.IProgress; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.VirtualBoxManager; +import org.virtualbox_4_1.*; import com.google.common.base.Function; @@ -48,9 +45,8 @@ import com.google.common.base.Function; * found. VBOX_E_INVALID_OBJECT_STATE: Session already open or being opened. * VBOX_E_IPRT_ERROR: Launching process for machine failed. VBOX_E_VM_ERROR: * Failed to assign machine to session. - * + * * @author Mattias Holmqvist - * * @see ErrorCode */ public class LaunchMachineIfNotAlreadyRunning implements Function { @@ -73,7 +69,7 @@ public class LaunchMachineIfNotAlreadyRunning implements Function Date: Sat, 29 Oct 2011 22:47:47 +0200 Subject: [PATCH 08/10] Added UnregisterMachineIfExists function to cleanup image machines before running IsoToIMachineLiveTest --- .../admin/UnregisterMachineIfExists.java | 67 +++++++++++++++++++ .../functions/IsoToIMachineLiveTest.java | 6 +- .../admin/UnregisterMachineIfExistsTest.java | 56 ++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExists.java create mode 100644 sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsTest.java diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExists.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExists.java new file mode 100644 index 0000000000..08d2d25668 --- /dev/null +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExists.java @@ -0,0 +1,67 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.virtualbox.functions.admin; + + +import com.google.common.base.Function; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.virtualbox.domain.ErrorCode; +import org.virtualbox_4_1.CleanupMode; +import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_1.VirtualBoxManager; + +import javax.annotation.Nullable; +import javax.annotation.Resource; +import javax.inject.Named; + +public class UnregisterMachineIfExists implements Function { + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private VirtualBoxManager manager; + private CleanupMode mode; + + public UnregisterMachineIfExists(VirtualBoxManager manager, CleanupMode mode) { + this.manager = manager; + this.mode = mode; + } + + @Override + public Void apply(@Nullable String vmName) { + try { + IMachine machine = manager.getVBox().findMachine(vmName); + machine.unregister(mode); + } catch (VBoxException e) { + ErrorCode errorCode = ErrorCode.valueOf(e); + switch (errorCode) { + case VBOX_E_OBJECT_NOT_FOUND: + logger.debug("Machine %s does not exists, cannot unregister", vmName); + break; + default: + throw e; + } + } + return null; + } +} diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineLiveTest.java index eb7286d382..0f5d194a21 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineLiveTest.java @@ -36,8 +36,12 @@ import org.jclouds.domain.Credentials; import org.jclouds.json.Json; import org.jclouds.json.config.GsonModule; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; +import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExists; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import org.virtualbox_4_1.CleanupMode; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.VirtualBoxManager; @@ -69,9 +73,9 @@ public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest { public void setUp() throws Exception { identity = "toor"; credential = "password"; + new UnregisterMachineIfExists(manager, CleanupMode.Full).apply(vmName); } - @Test public void testCreateImageMachineFromIso() throws Exception { VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi(); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsTest.java new file mode 100644 index 0000000000..e0c3628c4d --- /dev/null +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/UnregisterMachineIfExistsTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.virtualbox.functions.admin; + +import org.testng.annotations.Test; +import org.virtualbox_4_1.*; + +import java.util.Collections; +import java.util.List; + +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.expect; +import static org.easymock.classextension.EasyMock.*; + +@Test(groups = "unit", testName = "UnregisterMachineIfExistsTest") +public class UnregisterMachineIfExistsTest { + + @Test + public void testUnregisterExistingMachine() throws Exception { + VirtualBoxManager manager = createMock(VirtualBoxManager.class); + IVirtualBox vBox = createMock(IVirtualBox.class); + IMachine registeredMachine = createMock(IMachine.class); + List mediums = Collections.emptyList(); + + CleanupMode mode = CleanupMode.Full; + String vmName = "jclouds-image-example-machine"; + + expect(manager.getVBox()).andReturn(vBox).anyTimes(); + expect(vBox.findMachine(vmName)).andReturn(registeredMachine); + + expect(registeredMachine.unregister(mode)).andReturn(mediums); + expectLastCall().anyTimes(); + + replay(manager, vBox, registeredMachine); + + new UnregisterMachineIfExists(manager, mode).apply(vmName); + } + +} From 45bf2b4248a117677ad234c57b7a23335081d6e3 Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Sun, 30 Oct 2011 00:02:11 +0200 Subject: [PATCH 09/10] Changed IsoToIMachine to run in headless mode. --- .../java/org/jclouds/virtualbox/functions/IsoToIMachine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java index 9cd2458158..13e2b6bc69 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java @@ -190,7 +190,7 @@ public class IsoToIMachine implements Function { } private void ensureMachineIsLaunched(String vmName) { - applyForMachine(manager, vmName, new LaunchMachineIfNotAlreadyRunning(manager, ExecutionType.GUI, "")); + applyForMachine(manager, vmName, new LaunchMachineIfNotAlreadyRunning(manager, ExecutionType.HEADLESS, "")); } private void ensureGuestAdditionsMediumIsAttached(String vmName, final IMedium guestAdditionsDvdMedium) { From 06f418c8ba54e3ebfa4031fb75231b082a4ae91f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 31 Oct 2011 09:31:26 +0000 Subject: [PATCH 10/10] added another sshj test --- .../sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java index b08da4a75b..507fc8fa5c 100644 --- a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java +++ b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java @@ -87,6 +87,8 @@ public class SshjSshClientTest { } public void testExceptionClassesRetry() { + assert ssh.shouldRetry(new ConnectionException("Read timed out", new SSHException("Read timed out", + new SocketTimeoutException("Read timed out")))); assert ssh.shouldRetry(new SocketTimeoutException("connect timed out")); assert ssh.shouldRetry(new TransportException("socket closed")); assert ssh.shouldRetry(new ConnectionException("problem"));