Author: adietish
Date: 2010-12-15 04:55:06 -0500 (Wed, 15 Dec 2010)
New Revision: 27492
Added:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/job/
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/job/SchedulingRulesTest.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/InstanceSchedulingRule.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/ChangeLog
Log:
[JBIDE-7594]
* corrected scheduling rules to have correct blocking across the scheduling class
hierarchy
* created #createSecurePasswordStore to be able to fake store in tests
* created tests for all scheduling rules
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-15 08:34:42
UTC (rev 27491)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-15 09:55:06
UTC (rev 27492)
@@ -1,3 +1,12 @@
+2010-12-15 André Dietisheim <adietish(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/job/InstanceSchedulingRule.java (isConflicting):
+ * src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java (isConflicting):
+ * src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java
(isConflicting):
+ [JBIDE-7594] corrected scheduling rules to have correct blocking across the scheduling
class hierarchy
+ * src/org/jboss/tools/deltacloud/core/DeltaCloud.java (createSecurePasswordStore):
+ [JBIDE-7594] created #createSecurePasswordStore to be able to fake store in tests
+
2010-12-14 André Dietisheim <adietish(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java (updateInstance):
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-12-15
08:34:42 UTC (rev 27491)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-12-15
09:55:06 UTC (rev 27492)
@@ -92,7 +92,7 @@
this.name = name;
this.username = username;
this.type = type;
- this.passwordStore = new SecurePasswordStore(new DeltaCloudPasswordStorageKey(name,
username), password);
+ this.passwordStore = createSecurePasswordStore(name, username, password);
this.client = createClient(name, url, username, passwordStore.getPassword());
imageFilter = createImageFilter(imageFilterRules);
instanceFilter = createInstanceFilter(instanceFilterRules);
@@ -148,7 +148,11 @@
|| (thisObject == null && thatObject == null);
}
- private InternalDeltaCloudClient createClient(String name, String url, String username,
String password)
+ protected SecurePasswordStore createSecurePasswordStore(String name2, String username2,
String password) {
+ return new SecurePasswordStore(new DeltaCloudPasswordStorageKey(name, username),
password);
+ }
+
+ protected InternalDeltaCloudClient createClient(String name, String url, String
username, String password)
throws DeltaCloudException {
try {
return new DeltaCloudClientImpl(url, username, password);
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-12-15
08:34:42 UTC (rev 27491)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-12-15
09:55:06 UTC (rev 27492)
@@ -58,7 +58,7 @@
@XmlElement(name = "private_addresses")
private AddressList privateAddresses;
- private Instance() {
+ public Instance() {
}
@SuppressWarnings("unused")
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java 2010-12-15
08:34:42 UTC (rev 27491)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java 2010-12-15
09:55:06 UTC (rev 27492)
@@ -31,20 +31,27 @@
@Override
public boolean isConflicting(ISchedulingRule rule) {
- return super.isConflicting(rule)
- && isOnSameElement(rule);
+ if (super.isConflicting(rule)) {
+ if (isCloudElementSchedulingRule(rule)) {
+ return isOnSameElement((CloudElementSchedulingRule) rule);
+ }
+ return true;
+ }
+ return false;
}
private boolean isOnSameElement(ISchedulingRule rule) {
- if (CloudElementSchedulingRule.class.isAssignableFrom(rule.getClass())) {
- return ((CloudElementSchedulingRule) rule).getCloudElement().equals(element);
+ if (isCloudElementSchedulingRule(rule)) {
+ return element.equals(((CloudElementSchedulingRule) rule).getCloudElement());
} else {
- // this rules conflicts with a cloud rule which is not an element
- // rule
- return true;
+ return false;
}
}
+ private boolean isCloudElementSchedulingRule(ISchedulingRule rule) {
+ return CloudElementSchedulingRule.class.isAssignableFrom(rule.getClass());
+ }
+
private CLOUDELEMENT getCloudElement() {
return element;
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java 2010-12-15
08:34:42 UTC (rev 27491)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java 2010-12-15
09:55:06 UTC (rev 27492)
@@ -54,9 +54,11 @@
return cloud;
}
+ @Override
public String toString() {
return new StringBuilder()
- .append("[InstanceSchedulingRule ")
+ .append("[CloudSchedulingRule ")
+ .append("(a)").append(System.identityHashCode(this)).append(" ")
.append("cloud :\"")
.append(getCloud().getName())
.append("\"")
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/InstanceSchedulingRule.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/InstanceSchedulingRule.java 2010-12-15
08:34:42 UTC (rev 27491)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/InstanceSchedulingRule.java 2010-12-15
09:55:06 UTC (rev 27492)
@@ -32,23 +32,28 @@
@Override
public boolean isConflicting(ISchedulingRule rule) {
- return super.isConflicting(rule)
- && isOnSameInstance(rule);
- }
-
- private boolean isOnSameInstance(ISchedulingRule rule) {
- if (InstanceSchedulingRule.class.isAssignableFrom(rule.getClass())) {
- return instance.equals(((InstanceSchedulingRule) rule).getInstance());
- } else {
- // this rules conflicts with a cloud element rule which is not an instance rule
+ if (super.isConflicting(rule)) {
+ if (isInstanceSchedulingRule(rule)) {
+ return isOnSameInstance((InstanceSchedulingRule) rule);
+ }
return true;
}
+ return false;
}
-
+
+ private boolean isOnSameInstance(InstanceSchedulingRule rule) {
+ return instance.equals(((InstanceSchedulingRule) rule).getInstance());
+ }
+
+ private boolean isInstanceSchedulingRule(ISchedulingRule rule) {
+ return InstanceSchedulingRule.class.isAssignableFrom(rule.getClass());
+ }
+
protected DeltaCloudInstance getInstance() {
return instance;
}
+ @Override
public String toString() {
return new StringBuilder()
.append("[InstanceSchedulingRule ")
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/ChangeLog
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/ChangeLog 2010-12-15 08:34:42
UTC (rev 27491)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/ChangeLog 2010-12-15 09:55:06
UTC (rev 27492)
@@ -1,3 +1,8 @@
+2010-12-15 André Dietisheim <adietish(a)redhat.com>
+
+ * src/org/jboss/tools/internal/deltacloud/test/core/job/SchedulingRulesTest.java:
+ [JBIDE-7594] created tests for all scheduling rules
+
2010-11-19 André Dietisheim <adietish(a)redhat.com>
*
src/org/jboss/tools/internal/deltacloud/test/core/client/InstanceMockIntegrationTest.java:
Added:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/job/SchedulingRulesTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/job/SchedulingRulesTest.java
(rev 0)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/job/SchedulingRulesTest.java 2010-12-15
09:55:06 UTC (rev 27492)
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.internal.deltacloud.test.core.job;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
+import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+import org.jboss.tools.deltacloud.core.SecurePasswordStore;
+import org.jboss.tools.deltacloud.core.client.Instance;
+import org.jboss.tools.deltacloud.core.job.AbstractCloudElementJob;
+import org.jboss.tools.deltacloud.core.job.AbstractCloudElementJob.CLOUDELEMENT;
+import org.jboss.tools.deltacloud.core.job.CloudElementSchedulingRule;
+import org.jboss.tools.deltacloud.core.job.CloudSchedulingRule;
+import org.jboss.tools.deltacloud.core.job.InstanceSchedulingRule;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author André Dietisheim
+ */
+public class SchedulingRulesTest {
+
+ private DeltaCloudFake cloudFake;
+ private Instance instanceFake;
+ private DeltaCloudInstance deltaCloudInstanceFake;
+
+ @Before
+ public void setUp() throws DeltaCloudException {
+ this.cloudFake = new DeltaCloudFake();
+ this.instanceFake = new Instance();
+ this.deltaCloudInstanceFake = new DeltaCloudInstance(cloudFake, instanceFake);
+ }
+
+ @Test
+ public void instanceRule2InstanceRule() throws DeltaCloudException {
+ InstanceSchedulingRule instanceRule =
+ new InstanceSchedulingRule(cloudFake, CLOUDELEMENT.INSTANCES,
deltaCloudInstanceFake);
+ assertTrue(instanceRule.isConflicting(instanceRule));
+ }
+
+ @Test
+ public void instanceRule2CloudElementInstanceRule() throws DeltaCloudException {
+ InstanceSchedulingRule instanceRule = new InstanceSchedulingRule(
+ cloudFake, AbstractCloudElementJob.CLOUDELEMENT.INSTANCES, deltaCloudInstanceFake);
+ CloudElementSchedulingRule cloudRule =
+ new CloudElementSchedulingRule(cloudFake, CLOUDELEMENT.INSTANCES);
+ assertTrue(instanceRule.isConflicting(cloudRule));
+ }
+
+ @Test
+ public void instanceRule2CloudElementImageRule() throws DeltaCloudException {
+ InstanceSchedulingRule instanceRule =
+ new InstanceSchedulingRule(cloudFake, CLOUDELEMENT.INSTANCES,
deltaCloudInstanceFake);
+ CloudElementSchedulingRule cloudRule = new CloudElementSchedulingRule(cloudFake,
CLOUDELEMENT.IMAGES);
+ assertFalse(instanceRule.isConflicting(cloudRule));
+ }
+
+ @Test
+ public void instanceRule2CloudRule() throws DeltaCloudException {
+ InstanceSchedulingRule instanceRule =
+ new InstanceSchedulingRule(cloudFake, CLOUDELEMENT.INSTANCES,
deltaCloudInstanceFake);
+ CloudSchedulingRule cloudRule = new CloudSchedulingRule(cloudFake);
+ assertTrue(instanceRule.isConflicting(cloudRule));
+ }
+
+ @Test
+ public void cloudInstancesRule2CloudInstancesRule() throws DeltaCloudException {
+ CloudElementSchedulingRule cloudInstancesRule =
+ new CloudElementSchedulingRule(cloudFake, CLOUDELEMENT.INSTANCES);
+ assertTrue(cloudInstancesRule.isConflicting(cloudInstancesRule));
+ }
+
+ @Test
+ public void cloudInstancesRule2CloudImageRule() throws DeltaCloudException {
+ CloudElementSchedulingRule cloudInstancesRule =
+ new CloudElementSchedulingRule(cloudFake, CLOUDELEMENT.INSTANCES);
+ CloudElementSchedulingRule cloudImagesRule =
+ new CloudElementSchedulingRule(cloudFake, CLOUDELEMENT.IMAGES);
+ assertFalse(cloudInstancesRule.isConflicting(cloudImagesRule));
+ }
+
+ @Test
+ public void cloudInstancesRule2CloudRule() throws DeltaCloudException {
+ CloudElementSchedulingRule cloudInstancesRule =
+ new CloudElementSchedulingRule(cloudFake, CLOUDELEMENT.INSTANCES);
+ CloudSchedulingRule cloudRule = new CloudSchedulingRule(cloudFake);
+ assertTrue(cloudInstancesRule.isConflicting(cloudRule));
+ }
+
+ private static class DeltaCloudFake extends DeltaCloud {
+
+ public DeltaCloudFake() throws DeltaCloudException {
+ super("mock", "http://dummy.org", "dummyUser",
"dummyPassword");
+ }
+
+ @Override
+ protected SecurePasswordStore createSecurePasswordStore(String name, String username,
String password) {
+ return new SecurePasswordStoreFake("dummyPassword");
+ }
+ }
+
+ private static class SecurePasswordStoreFake extends SecurePasswordStore {
+
+ private String password;
+
+ public SecurePasswordStoreFake(String password) {
+ super(null, password);
+ this.password = password;
+ }
+
+ @Override
+ public String getPassword() throws DeltaCloudException {
+ return password;
+ }
+
+ @Override
+ public void setPassword(String password) throws DeltaCloudException {
+ this.password = password;
+ }
+
+ @Override
+ public void update(IStorageKey key, String password) throws DeltaCloudException {
+ setPassword(password);
+ }
+
+ @Override
+ public void remove() throws DeltaCloudException {
+ }
+
+ }
+}
Property changes on:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/job/SchedulingRulesTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain