1 10 package org.mmbase.tests; 11 import org.mmbase.bridge.*; 12 13 19 public abstract class BridgeTest extends MMBaseTest { 20 21 public BridgeTest() { 22 super(); 23 } 24 public BridgeTest(String name) { 25 super(name); 26 } 27 28 int tryCount = 0; 29 30 protected Cloud getCloud() { 31 Cloud c = null; 32 while(c == null) { 33 CloudContext cc = null; 34 try { 35 cc = ContextProvider.getDefaultCloudContext(); 36 c = cc.getCloud("mmbase", "class", null); 37 break; 38 } catch (BridgeException be) { 39 if (cc instanceof LocalContext) { 40 throw be; 41 } 42 System.out.println(be.getMessage() + ". LOCAL. Perhaps mmbase not yet running, retrying in 5 seconds (" + tryCount + ")"); 43 try { 44 tryCount ++; 45 Thread.sleep(5000); 46 } catch (Exception ie) { 47 return null; 48 } 49 if (tryCount > 25) { 50 throw be; 51 } 52 } 53 } 54 ensureDeployed(c, "local cloud"); 55 return c; 56 } 57 58 protected Cloud getRemoteCloud() { 59 return getRemoteCloud("rmi://127.0.0.1:1221/remotecontext"); 60 } 61 62 protected Cloud getRemoteCloud(String uri) { 63 Cloud c = null; 64 while(c == null) { 65 try { 66 c = ContextProvider.getCloudContext(uri).getCloud("mmbase", "class", null); 67 break; 68 } catch (BridgeException be) { 69 System.out.println(be.getMessage() + ". " + uri + ". Perhaps mmbase '" + uri + "' not yet running, retrying in 5 seconds (" + tryCount + ")"); 70 try { 71 tryCount ++; 72 Thread.sleep(5000); 73 } catch (Exception ie) { 74 return null; 75 } 76 if (tryCount > 25) throw be; 77 } 78 } 79 ensureDeployed(c, uri); 80 return c; 81 82 } 83 84 protected void ensureDeployed(Cloud cloud, String uri) { 85 while(true) { 86 if (cloud.hasRelationManager("bb", "cc", "posrel") && 88 cloud.hasRelationManager("aa", "bb", "related") && 89 cloud.hasRelationManager("bb", "aa", "related") 90 ) { 91 return; 92 } 93 if (!cloud.hasRelationManager("bb", "cc", "posrel")) { 94 System.out.println("No relation bb--(posrel)-->cc, in '" + uri + "' perhaps BridgeTest application not yet deployed. Waiting another 5 seconds (" + tryCount + ")"); 95 } else if (!cloud.hasRelationManager("aa", "bb", "related")) { 96 System.out.println("No relation aa--(related)-->bb, in '" + uri + "' perhaps BridgeTest application not yet deployed. Waiting another 5 seconds (" + tryCount + ")"); 97 } else if (!cloud.hasRelationManager("bb", "aa", "related")) { 98 System.out.println("No relation bb--(related)-->aa, in '" + uri + "' perhaps BridgeTest application not yet deployed. Waiting another 5 seconds (" + tryCount + ")"); 99 } 100 try { 101 tryCount ++; 102 Thread.sleep(5000); 103 if (tryCount > 25) { 104 System.err.println("Giving up"); 105 return; 106 }; 107 } catch (InterruptedException ie) { 108 return; 109 } 110 } 111 } 112 113 } 114 | Popular Tags |