From c4800a6c1b96b327f7f964ebf468348624363abf Mon Sep 17 00:00:00 2001 From: dougsleite Date: Thu, 29 Oct 2009 18:45:38 +0000 Subject: - Changing the implementation-guardian to work with the policy-guardianException module - Adding the policy-guardianException module: The guardian member is implemented as policies git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@831060 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/java/definitions.xml | 28 ++++++++ .../guardian/GuardianImplementationTest.java | 77 ---------------------- .../guardian/itests/primaryBackup/common/Node.java | 2 + .../itests/primaryBackup/common/NodeImpl.java | 43 ++++++------ .../primaryBackup/concurrentExceptions/Launch.java | 4 ++ .../itests/primaryBackup/simple/Launch.java | 2 + .../itests/primaryBackup/simple/Launch2.java | 2 + 7 files changed, 61 insertions(+), 97 deletions(-) create mode 100644 sandbox/dougsleite/implementation-guardian/src/test/java/definitions.xml delete mode 100644 sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/GuardianImplementationTest.java (limited to 'sandbox/dougsleite/implementation-guardian/src/test') diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/definitions.xml b/sandbox/dougsleite/implementation-guardian/src/test/java/definitions.xml new file mode 100644 index 0000000000..0793e69334 --- /dev/null +++ b/sandbox/dougsleite/implementation-guardian/src/test/java/definitions.xml @@ -0,0 +1,28 @@ + + + + + + + + \ No newline at end of file diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/GuardianImplementationTest.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/GuardianImplementationTest.java deleted file mode 100644 index ba4f6230d8..0000000000 --- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/GuardianImplementationTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.tuscany.sca.implementation.guardian; - -import org.apache.tuscany.sca.implementation.guardian.*; -import org.apache.tuscany.sca.host.embedded.SCADomain; -import org.apache.tuscany.sca.implementation.guardian.common.Context; -import org.apache.tuscany.sca.implementation.guardian.common.GlobalException; -import org.apache.tuscany.sca.implementation.guardian.impl.GuardianMemberImpl; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class GuardianImplementationTest { - -// private SCADomain scaDomain; -// private GuardianGroup guardian; -// -// @Before -// public void init() throws Exception { -// scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/implementation/guardian/guardianTest.composite"); -// guardian = scaDomain.getService(GuardianGroup.class, "GuardianComponent"); -// } -// -// @Test -// public void enabelContextTest() throws Exception { -// guardian.enableContext(Context.INIT_CONTEXT); -// } -// -// @After -// public void destroy() { -// scaDomain.close(); -// } - public static void main(String... args) { - - SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/implementation/guardian/guardianTest.composite"); - GuardianGroup guardian = scaDomain.getService(GuardianGroup.class, "GuardianComponent"); - - System.out.println("\n#EnableContext invocation"); - guardian.enableContext(Context.INIT_CONTEXT); - - System.out.println("\n#RemoveContext invocation"); - guardian.removeContext(); - - System.out.println("\n#CheckExceptionStatus invocation"); - guardian.checkExceptionStatus(); - - System.out.println("\n#CheckExceptionStatus invocation"); - boolean value = guardian.propagate(new GlobalException()); - System.out.println("returned value: " + value); - - System.out.println("\n#AddGuardianMember invocation"); - guardian.addGuardianMember(new GuardianMemberImpl()); - - System.out.println("\n#RemoveGuardianMember invocation"); - value = guardian.removeGuardianMember(new GuardianMemberImpl()); - System.out.println("returned value: " + value); - - } - -} diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/Node.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/Node.java index 6aa9456816..8890f631d4 100644 --- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/Node.java +++ b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/Node.java @@ -34,4 +34,6 @@ public interface Node { public void kill(); public boolean isDead(); + + public void setID(String pID); } diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/NodeImpl.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/NodeImpl.java index 37f4f529f0..6004468f73 100644 --- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/NodeImpl.java +++ b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/NodeImpl.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Queue; import java.util.logging.Level; import java.util.logging.Logger; +import org.apache.tuscany.sca.implementation.guardian.GuardianGroup; import org.apache.tuscany.sca.implementation.guardian.GuardianMember; import org.apache.tuscany.sca.implementation.guardian.common.Context; import org.osoa.sca.annotations.Init; @@ -42,8 +43,8 @@ public class NodeImpl implements Node, TestInterface { private int role; private String pID; private Queue updates; - @Reference(name = "guardian_member", required = true) - public GuardianMember gm; + @Reference(name = "guardian", required = true) + public GuardianGroup guardianGroup; @Reference(name = "nodes", required = true) public List nodeList; private boolean forcePSFException; @@ -73,15 +74,14 @@ public class NodeImpl implements Node, TestInterface { forceAUFException = false; } - @Init - public void init() { - pID = gm.getParticipantIdentifier(); + public void setID(String pID) { + this.pID = pID; } @OneWay public void execute() { isDead = false; - gm.enableContext(mainContext); + guardianGroup.enableContext(mainContext); role = PRIMARY; while (true) { @@ -92,7 +92,7 @@ public class NodeImpl implements Node, TestInterface { System.out.println(pID + "#Main context: "); sleep(pID + "#Sleeping at main context...", 4000); - gm.checkExceptionStatus(); + guardianGroup.checkExceptionStatus(); if (role == PRIMARY) { //Config as primary then... @@ -109,12 +109,13 @@ public class NodeImpl implements Node, TestInterface { } catch (PrimaryFailedException ex) { System.out.println(pID + "# Exception captured!: PrimaryFailedException"); - System.out.println(pID + "#Needs propagation?: " + gm.propagate(ex)); + System.out.println(pID + "#Needs propagation?: " + guardianGroup.propagate(ex)); - if (gm.propagate(ex)) { + if (guardianGroup.propagate(ex)) { //throw ex; this.kill(); ex.printStackTrace(); + guardianGroup.removeContext(); return; } @@ -122,12 +123,14 @@ public class NodeImpl implements Node, TestInterface { } catch (BackupFailedException ex) { System.out.println(pID + "# Exception captured!: BackupFailedException"); - System.out.println(pID + "#Needs propagation?: " + gm.propagate(ex)); + System.out.println(pID + "#Needs propagation?: " + guardianGroup.propagate(ex)); - if (gm.propagate(ex)) { + if (guardianGroup.propagate(ex)) { //throw ex; this.kill(); ex.printStackTrace(); + + guardianGroup.removeContext(); return; } } @@ -141,14 +144,14 @@ public class NodeImpl implements Node, TestInterface { while (true) { - gm.enableContext(primaryContext); + guardianGroup.enableContext(primaryContext); //blockingCheck(); try { System.out.println(pID + "#Primary context: "); sleep(pID + "#Sleeping at primary context...", 4000); - gm.checkExceptionStatus(); + guardianGroup.checkExceptionStatus(); //Process the request then... System.out.println(pID + "#Processing the request..."); @@ -173,7 +176,7 @@ public class NodeImpl implements Node, TestInterface { } catch (PrimaryServiceFailureException ex) { System.out.println(pID + "# Exception captured!: PrimaryServiceFailureException"); - gm.gthrow(new PrimaryFailedException(), null); + guardianGroup.gthrow(new PrimaryFailedException(), null); } catch (BackupFailedException ex) { System.out.println(pID + "# Exception captured!: BackupFailedException"); //backupAvailable = false; @@ -182,7 +185,7 @@ public class NodeImpl implements Node, TestInterface { System.out.println(pID + "# Exception captured!: BackupJoinedException"); backupAvailable = true; } finally { - gm.removeContext(); + guardianGroup.removeContext(); } } } @@ -206,14 +209,14 @@ public class NodeImpl implements Node, TestInterface { private void backupService() { while (true) { - gm.enableContext(backupContext); + guardianGroup.enableContext(backupContext); //blockingCheck(); try { System.out.println(pID + "#Backup context: "); sleep(pID + "#Sleeping at backup service", 4000); - gm.checkExceptionStatus(); + guardianGroup.checkExceptionStatus(); applyUpdate(); @@ -223,15 +226,15 @@ public class NodeImpl implements Node, TestInterface { } catch (ApplyUpdateFailureException ex) { System.out.println(pID + "# Exception captured!: ApplyUpdateFailureException"); - gm.gthrow(new BackupFailedException(), null); + guardianGroup.gthrow(new BackupFailedException(), null); } finally { - gm.removeContext(); + guardianGroup.removeContext(); } } } public String getID() { - return gm.getParticipantIdentifier(); + return this.pID; } private void sleep(String msg, int millis) { diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/Launch.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/Launch.java index ab0c21dba6..169f8e50d4 100644 --- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/Launch.java +++ b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/Launch.java @@ -32,24 +32,28 @@ public class Launch { System.out.println("Starting participat1..."); Node c = scaDomain.getService(Node.class, "Participant1"); + c.setID("Participant1"); c.execute(); System.in.read(); System.out.println("Starting participant2..."); Node c2 = scaDomain.getService(Node.class, "Participant2"); + c2.setID("Participant2"); c2.execute(); System.in.read(); System.out.println("Starting participant3..."); Node c3 = scaDomain.getService(Node.class, "Participant3"); + c3.setID("Participant3"); c3.execute(); System.in.read(); System.out.println("Starting participant4..."); Node c4 = scaDomain.getService(Node.class, "Participant4"); + c4.setID("Participant4"); c4.execute(); System.in.read(); diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch.java index 86df9bc5f9..1206d45db2 100644 --- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch.java +++ b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch.java @@ -32,12 +32,14 @@ public class Launch { System.out.println("Starting participat1..."); Node c = scaDomain.getService(Node.class, "Participant1"); + c.setID("Participant1"); c.execute(); System.in.read(); System.out.println("Starting participant2..."); Node c2 = scaDomain.getService(Node.class, "Participant2"); + c2.setID("Participant2"); c2.execute(); System.in.read(); diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch2.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch2.java index 1c5fd26745..e08251e07a 100644 --- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch2.java +++ b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch2.java @@ -32,12 +32,14 @@ public class Launch2 { System.out.println("Starting participat1..."); Node c = scaDomain.getService(Node.class, "Participant1"); + c.setID("Participant1"); c.execute(); System.in.read(); System.out.println("Starting participant2..."); Node c2 = scaDomain.getService(Node.class, "Participant2"); + c2.setID("Participant2"); c2.execute(); System.in.read(); -- cgit v1.2.3