00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package gov.lanl.isr.sensix.test;
00036
00037 import junit.framework.*;
00038 import java.io.*;
00039 import gov.lanl.isr.sensix.*;
00040 import gov.lanl.isr.sensix.discovery.*;
00041 import gov.lanl.isr.sensix.sensing.*;
00042
00043
00044 public class CorbaThreeLevelTest extends TestCase
00045 {
00046 private class Runner extends Thread
00047 {
00048 private CorbaThreeLevelTest parent;
00049 private int which;
00050 private int num_levels;
00051 private byte debug_level;
00052 private boolean ready;
00053
00054 public Runner(CorbaThreeLevelTest test, int what, int lvls, byte dl) {
00055 parent = test;
00056 which = what;
00057 num_levels = lvls;
00058 debug_level = dl;
00059 ready = false;
00060 }
00061
00062 public void run() {
00063 String[] args = null;
00064 java.util.Properties prop = null;
00065
00066 try {
00067 switch (which) {
00068 case 0:
00069 parent.sclient = new SenseClient(30, num_levels,
00070 args, prop,
00071 "ClientTest_3." + num_levels,
00072 debug_level);
00073 ready = true;
00074 break;
00075
00076 case 1:
00077 parent.sserver_1 = new SenseServer(20, num_levels - 1,
00078 args, prop,
00079 "ServerTest_3." + (num_levels - 1),
00080 debug_level, null);
00081 ready = true;
00082 parent.sserver_1.run();
00083 break;
00084
00085 case 2:
00086 parent.sserver_2 = new SenseServer(10, 1, args, prop,
00087 "ServerTest_3.1",
00088 debug_level, null);
00089 ready = true;
00090 parent.sserver_2.run();
00091 break;
00092 }
00093 } catch (DiscoveryException de) {
00094 System.err.println("Discovery exception: " + de.description);
00095 de.printStackTrace(System.err);
00096 fail("Exception starting SENSIX Discovery service");
00097 } catch (Exception e) {
00098 System.err.println("Miscellaneous exception");
00099 e.printStackTrace(System.err);
00100 if (which == 0)
00101 fail("Exception starting SENSIX client: " + e.toString());
00102 else
00103 fail("Exception starting SENSIX server: " + e.toString());
00104 }
00105 }
00106
00107 public void check_ready() {
00108 while (!ready) {
00109 try {
00110 Thread.sleep(10);
00111 } catch (Exception e) {}
00112 }
00113 }
00114 }
00115
00116 public SenseClient sclient;
00117 public SenseServer sserver_1;
00118 public SenseServer sserver_2;
00119 protected Runner runc, runs1, runs2;
00120
00121 public static final boolean VERBOSE = true;
00122 public static final int INITIALIZATION = 500;
00123 public static final int INTERMEDIATE = 300;
00124 public static final boolean MESSAGE_DUMP = false;
00125
00126
00127 protected void setUp() {
00128 byte dl = 0;
00129 if (VERBOSE)
00130 dl = 2;
00131 System.err.println("START TEST");
00132
00133 runc = new Runner(this, 0, 3, dl);
00134 runc.start();
00135 runs1 = new Runner(this, 1, 3, dl);
00136 runs1.start();
00137 runs2 = new Runner(this, 2, 3, dl);
00138 runs2.start();
00139
00140 runc.check_ready();
00141 runs1.check_ready();
00142 runs2.check_ready();
00143 }
00144
00145
00146 protected void tearDown() {
00147 sclient.shutdown();
00148 sserver_1.shutdown();
00149 sserver_2.shutdown();
00150 try {
00151 runc.join();
00152 runs1.join();
00153 runs2.join();
00154 } catch (InterruptedException e) {}
00155 System.err.println("STOP TEST");
00156 String id = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
00157 try {
00158 FileWriter os = new FileWriter("jcorba." + id + ".msgct", true);
00159 os.write("--------------------\n");
00160 os.close();
00161 } catch (IOException e) {}
00162 if (MESSAGE_DUMP) {
00163 try {
00164 FileWriter os = new FileWriter("jcorba." + id + ".msgs", true);
00165 os.write("----------------------------------------\n");
00166 os.close();
00167 } catch (IOException e) {}
00168 }
00169 }
00170
00171
00172
00173 public void testStartStop() {
00174 try {
00175 Thread.sleep(INITIALIZATION);
00176 } catch (InterruptedException e) {
00177 System.err.println("Interruption");
00178 }
00179 }
00180
00181
00182 public void testThreeLevelTask() {
00183 try {
00184 Capability loc1 = (Capability)(new LocationImpl(37.505, -130.0302));
00185 sserver_1.addCapability(SenseCorba.GPS, loc1);
00186 Capability loc2 = (Capability)(new LocationImpl());
00187 sserver_2.addCapability(SenseCorba.GPS, loc2);
00188
00189 System.err.println("DISCOVERY END");
00190 Thread.sleep(INITIALIZATION);
00191
00192 String cmd = "recite(spatialseries(sense(sensor=GPS)))";
00193 Sensory f = SenseParser.senseParser(sclient.getPoa(), cmd);
00194 if (sclient.devolve(f) < 0)
00195 fail("Unexpected Discovery exception");
00196 System.err.println("COMMAND SENT");
00197 Thread.sleep(INTERMEDIATE);
00198
00199 Data[] array = f.results();
00200 if (array == null || array.length == 0 || array[0] == null)
00201 fail("NULL data");
00202 if (array.length < 8)
00203 fail("Not enough data");
00204 if (array[0].fresult() == 35.8880556) {
00205 assertEquals(array[0].fresult(), 35.8880556);
00206 assertEquals(array[1].fresult(), -106.3063889);
00207 assertEquals(array[2].fresult(), 2255.52);
00208 assertEquals(array[4].fresult(), 37.505);
00209 assertEquals(array[5].fresult(), -130.0302);
00210 assertEquals(array[6].fresult(), 0.0);
00211 } else {
00212 assertEquals(array[0].fresult(), 37.505);
00213 assertEquals(array[1].fresult(), -130.0302);
00214 assertEquals(array[2].fresult(), 0.0);
00215 assertEquals(array[4].fresult(), 35.8880556);
00216 assertEquals(array[5].fresult(), -106.3063889);
00217 assertEquals(array[6].fresult(), 2255.52);
00218 }
00219 f._release();
00220 System.err.println("DATA RECVD");
00221 } catch (ParseException e) {
00222 System.err.println("Parse Exception in test: ");
00223 e.printStackTrace(System.err);
00224 } catch (org.omg.CORBA.UserException e) {
00225 System.err.println("Servant not active in test: ");
00226 e.printStackTrace(System.err);
00227 } catch (java.io.IOException e) {
00228 System.err.println("I/O Exception in test: ");
00229 e.printStackTrace(System.err);
00230 } catch (InterruptedException e) {
00231 System.err.println("Interruption");
00232 }
00233 }
00234
00235
00236 public void testDetask() {
00237 try {
00238 Capability loc1 = (Capability)(new LocationImpl(37.505, -130.0302));
00239 sserver_1.addCapability(SenseCorba.GPS, loc1);
00240 Capability loc2 = (Capability)(new LocationImpl());
00241 sserver_2.addCapability(SenseCorba.GPS, loc2);
00242
00243 Thread.sleep(INITIALIZATION);
00244
00245 String cmd = "recite(spatialseries(sense(sensor=GPS)))";
00246 Sensory f = SenseParser.senseParser(sclient.getPoa(), cmd);
00247 if (sclient.devolve(f) < 0)
00248 fail("Unexpected Discovery exception");
00249
00250 Thread.sleep(50);
00251 sclient.detask(f);
00252
00253 Thread.sleep(INITIALIZATION);
00254 Data[] array = f.results();
00255
00256 if (array != null && array.length != 0
00257 && array.length != 4 && array.length != 8)
00258 fail("Task cancel failed: " + array.length);
00259 f._release();
00260 } catch (ParseException e) {
00261 System.err.println("Parse Exception in test: ");
00262 e.printStackTrace(System.err);
00263 } catch (org.omg.CORBA.UserException e) {
00264 System.err.println("Servant not active in test: ");
00265 e.printStackTrace(System.err);
00266 } catch (java.io.IOException e) {
00267 System.err.println("I/O Exception in test: ");
00268 e.printStackTrace(System.err);
00269 } catch (InterruptedException e) {
00270 System.err.println("Interruption");
00271 }
00272 }
00273
00274
00275 public void testReTasking() {
00276 try {
00277 Capability loc1 = (Capability)(new LocationImpl(37.505, -130.0302));
00278 sserver_1.addCapability(SenseCorba.GPS, loc1);
00279 Capability loc2 = (Capability)(new LocationImpl());
00280 sserver_2.addCapability(SenseCorba.GPS, loc2);
00281
00282 Thread.sleep(INITIALIZATION);
00283
00284 String cmd = "recite(spatialseries(sense(sensor=GPS)))";
00285 Sensory f = SenseParser.senseParser(sclient.getPoa(), cmd);
00286 if (sclient.devolve(f) < 0)
00287 fail("Unexpected Discovery exception");
00288
00289 Thread.sleep(INTERMEDIATE);
00290
00291 Data[] array = f.results();
00292 if (array == null || array.length == 0 || array[0] == null)
00293 fail("NULL data");
00294 if (array.length != 8)
00295 fail("Not enough data");
00296 if (array[0].fresult() == 35.8880556) {
00297 assertEquals(array[0].fresult(), 35.8880556);
00298 assertEquals(array[1].fresult(), -106.3063889);
00299 assertEquals(array[2].fresult(), 2255.52);
00300 assertEquals(array[4].fresult(), 37.505);
00301 assertEquals(array[5].fresult(), -130.0302);
00302 assertEquals(array[6].fresult(), 0.0);
00303 } else {
00304 assertEquals(array[0].fresult(), 37.505);
00305 assertEquals(array[1].fresult(), -130.0302);
00306 assertEquals(array[2].fresult(), 0.0);
00307 assertEquals(array[4].fresult(), 35.8880556);
00308 assertEquals(array[5].fresult(), -106.3063889);
00309 assertEquals(array[6].fresult(), 2255.52);
00310 }
00311 f._release();
00312
00313 cmd = "recite(spatialseries(sense(sensor=GPS)))";
00314 f = SenseParser.senseParser(sclient.getPoa(), cmd);
00315 if (sclient.devolve(f) < 0)
00316 fail("Unexpected Discovery exception");
00317
00318 Thread.sleep(INTERMEDIATE);
00319
00320 array = f.results();
00321 if (array == null || array.length == 0 || array[0] == null)
00322 fail("NULL data");
00323 if (array.length != 8)
00324 fail("Not enough data");
00325 if (array[0].fresult() == 35.8880556) {
00326 assertEquals(array[0].fresult(), 35.8880556);
00327 assertEquals(array[1].fresult(), -106.3063889);
00328 assertEquals(array[2].fresult(), 2255.52);
00329 assertEquals(array[4].fresult(), 37.505);
00330 assertEquals(array[5].fresult(), -130.0302);
00331 assertEquals(array[6].fresult(), 0.0);
00332 } else {
00333 assertEquals(array[0].fresult(), 37.505);
00334 assertEquals(array[1].fresult(), -130.0302);
00335 assertEquals(array[2].fresult(), 0.0);
00336 assertEquals(array[4].fresult(), 35.8880556);
00337 assertEquals(array[5].fresult(), -106.3063889);
00338 assertEquals(array[6].fresult(), 2255.52);
00339 }
00340 f._release();
00341
00342 cmd = "recite(spatialseries(sense(sensor=GPS)))";
00343 f = SenseParser.senseParser(sclient.getPoa(), cmd);
00344 if (sclient.devolve(f) < 0)
00345 fail("Unexpected Discovery exception");
00346
00347 Thread.sleep(INTERMEDIATE);
00348
00349 array = f.results();
00350 if (array == null || array.length == 0 || array[0] == null)
00351 fail("NULL data");
00352 if (array.length != 8)
00353 fail("Not enough data");
00354 if (array[0].fresult() == 35.8880556) {
00355 assertEquals(array[0].fresult(), 35.8880556);
00356 assertEquals(array[1].fresult(), -106.3063889);
00357 assertEquals(array[2].fresult(), 2255.52);
00358 assertEquals(array[4].fresult(), 37.505);
00359 assertEquals(array[5].fresult(), -130.0302);
00360 assertEquals(array[6].fresult(), 0.0);
00361 } else {
00362 assertEquals(array[0].fresult(), 37.505);
00363 assertEquals(array[1].fresult(), -130.0302);
00364 assertEquals(array[2].fresult(), 0.0);
00365 assertEquals(array[4].fresult(), 35.8880556);
00366 assertEquals(array[5].fresult(), -106.3063889);
00367 assertEquals(array[6].fresult(), 2255.52);
00368 }
00369 f._release();
00370 } catch (ParseException e) {
00371 System.err.println("Parse Exception in test: ");
00372 e.printStackTrace(System.err);
00373 } catch (org.omg.CORBA.UserException e) {
00374 System.err.println("Servant not active in test: ");
00375 e.printStackTrace(System.err);
00376 } catch (java.io.IOException e) {
00377 System.err.println("I/O Exception in test: ");
00378 e.printStackTrace(System.err);
00379 } catch (InterruptedException e) {
00380 System.err.println("Interruption");
00381 }
00382 }
00383 }