diff options
Diffstat (limited to 'java/rasj/test')
-rw-r--r-- | java/rasj/test/Makefile | 116 | ||||
-rw-r--r-- | java/rasj/test/Makefile.dep | 0 | ||||
-rw-r--r-- | java/rasj/test/MassLoadTest.java | 324 | ||||
-rw-r--r-- | java/rasj/test/Systemtest_rasj.java | 295 | ||||
-rw-r--r-- | java/rasj/test/TestDbTa.java | 549 | ||||
-rw-r--r-- | java/rasj/test/TestException.java | 361 | ||||
-rw-r--r-- | java/rasj/test/TestHttp.java | 642 | ||||
-rw-r--r-- | java/rasj/test/TestMArray.java | 904 | ||||
-rw-r--r-- | java/rasj/test/TestOdmg.java | 430 | ||||
-rw-r--r-- | java/rasj/test/TestQuery.java | 143 | ||||
-rw-r--r-- | java/rasj/test/TestQuery.sh | 9 | ||||
-rw-r--r-- | java/rasj/test/TestRasInterval.java | 314 | ||||
-rw-r--r-- | java/rasj/test/TestRasPoint.java | 373 | ||||
-rw-r--r-- | java/rasj/test/count.sh | 11 | ||||
-rw-r--r-- | java/rasj/test/httptest.java | 53 | ||||
-rw-r--r-- | java/rasj/test/testEva.java | 229 | ||||
-rw-r--r-- | java/rasj/test/testIntervals.java | 326 | ||||
-rw-r--r-- | java/rasj/test/testMArrays.java | 871 |
18 files changed, 5950 insertions, 0 deletions
diff --git a/java/rasj/test/Makefile b/java/rasj/test/Makefile new file mode 100644 index 0000000..2538fb1 --- /dev/null +++ b/java/rasj/test/Makefile @@ -0,0 +1,116 @@ +# -*-Makefile-*- (for Emacs) +# +# This file is part of rasdaman community. +# +# Rasdaman community is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Rasdaman community is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +# +# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +# rasdaman GmbH. +# +# For more information please see <http://www.rasdaman.org> +# or contact Peter Baumann via <baumann@rasdaman.com>. # Top Level makefile. This points to the various modules that have to be build +# and/or deployed +# +# MAKEFILE FOR: +# package RasJ +# +# COMMENTS: +# - incomplete! +# - not part of systemtest: TestHttp.java +# - test env settings to be taken from next higher Makefile when ready +# - move .log manually to .log.orig if you want to set this as new reference output +################################################################## +######################### Definitions ############################ + +# standard include with general options +include $(RMANBASE)/Makefile.inc + +SRCS = TestRasPoint.java TestRasInterval.java TestMArray.java \ + TestException.java TestDbTa.java TestOdmg.java TestQuery.java \ + MassLoadTest.java + +OBJS = ${SRCS:%.java=%.class} + +# test programs (java needs them without .class suffix) +TESTS = TestRasPoint TestRasInterval TestDbTa TestException +# TESTS = ${OBJS:%.class=%} + +MISCCLEAN = *.class *.log + +# FIXME: should make use of general variable +JAVA = java +# Java options needed for testing +JAVAOPTS = -cp .:$(CLASSPATH) + +# directory where HTML documentation is created +DOCDIR := $(DOCBASE)/java/rasj/test + +########################### Targets ############################## + +# compile everything +.PHONY : all +all: $(OBJS) + +# run the test for all classes, compare log generated with archived log, abort on first error +.PHONY: systemtest +systemtest: $(TESTS) + +# later this should be of that structure: +# $(JAVA) $(JAVAOPTS) $@ > $@.log && diff $@.log.orig $@.log + +TestRasPoint: TestRasPoint.class + $(JAVA) $(JAVAOPTS) $@ + +TestRasInterval: TestRasInterval.class + $(JAVA) $(JAVAOPTS) $@ + +TestMArray: TestMArray.class + $(JAVA) $(JAVAOPTS) $@ --server NONE_YET --database RASBASE --collname NONEXISTENT + +MassLoadTest: MassLoadTest.class + $(JAVA) $(JAVAOPTS) $@ --server $(SERVER) --port $(PORT) --database $(DATABASE) --user $(USER) --passwd $(PASSWD) + +TestException: TestException.class + $(JAVA) $(JAVAOPTS) $@ --server $(SERVER) --port $(PORT) --database $(DATABASE) --user $(USER) --passwd $(PASSWD) + +TestDbTa: TestDbTa.class + $(JAVA) $(JAVAOPTS) $@ --server $(SERVER) --port $(PORT) --database $(DATABASE) --user $(USER) --passwd $(PASSWD) + +TestOdmg: TestOdmg.class + $(JAVA) $(JAVAOPTS) $@ --server $(SERVER) --port $(PORT) --database $(DATABASE) --user $(USER) --passwd $(PASSWD) + +TestQuery: TestQuery.class + $(JAVA) $(JAVAOPTS) $@ + +# not part of systemtest: TestHttp.java + +# create javadoc HTML doc: +.PHONY: docu +docu: $(SRCS) + -mkdir -p $(DOCDIR_RASJTEST) + $(JAVADOC) -private -author -d $(DOCDIR_RASJTEST) -sourcepath . *.java + +# remove all that can be generated +clean: + -rm -f $(MISCCLEAN) + -rm -rf $(DOCDIR) + +# delete all files +empty: + -rm -f $(SRCS) $(MISCCLEAN) + +############################ Dependencies ####################### + +# general rules +include $(RMANBASE)/Makefile.rel diff --git a/java/rasj/test/Makefile.dep b/java/rasj/test/Makefile.dep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/java/rasj/test/Makefile.dep diff --git a/java/rasj/test/MassLoadTest.java b/java/rasj/test/MassLoadTest.java new file mode 100644 index 0000000..6ec4fbe --- /dev/null +++ b/java/rasj/test/MassLoadTest.java @@ -0,0 +1,324 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +package rasj.test; + +import rasj.*; +import rasj.global.*; +import org.odmg.*; + +import java.util.*; +import java.io.*; + + +public class MassLoadTest implements RasGlobalDefs +{ + + public static void main(String[] args) + { + + String hostname = null; + String port = null; + Database mydb = null; + Transaction myta = null; + RasGMArray myMDD = null; + Implementation myApp = null; + OQLQuery myQuery = null; + String collectionName = "testCollection"; + int tileSize = 1000; + int overallSize = 200000; + int commitInterval = 50; + + + /******************************************* + * * + * Usage: MassLoadTest hostname [port] * + * * + *******************************************/ + + // we need the hostname + if(args.length>0 && args[0] == null) + { + System.out.println("Please provide the hostname as a parameter when calling this test-program."); + System.exit(-1); + } + else + hostname = args[0]; + + // is there a port specified? + if(args.length>1 && args[1] != null) + port = args[1]; + else + port = "8080"; + + try { + myApp = new RasImplementation("http://" + hostname + ":" + port); + mydb = myApp.newDatabase(); + System.err.println("Open Database ..."); + mydb.open("RASBASE",Database.OPEN_READ_WRITE); + System.err.println(" ok."); + myta = myApp.newTransaction(); + System.err.println("Begin transaction ..."); + myta.begin(); + System.err.println(" ok."); + + //create test collection + System.err.println("Create a test collection ..."); + myQuery = myApp.newOQLQuery(); + myQuery.create("create collection $1 GreySet"); + //myQuery.create("drop collection $1"); + + myQuery.bind(collectionName); + myQuery.execute(); + System.err.println(" ok."); + myta.commit(); + + // init insertion tile + System.err.println("create test arrays ..."); + myMDD = new RasGMArray(new RasMInterval("[0:" + (tileSize-1) + ",0:" + (tileSize-1) + "]"),1); + int cells = tileSize*tileSize; + byte[] mydata = new byte[cells]; + for(int i = 0; i < cells; i++) + mydata[i]=0; + myMDD.setArray(mydata); + myMDD.setObjectTypeName("GreyImage"); + + // now insert tiles + boolean first = true; + myta.begin(); + int dimX = 0; + int dimY = 0; + String domain = null; + int finished = 1; + + int counter = (int)Math.abs(overallSize/tileSize); + for(int x = 0; x < counter; x++) + { + dimX += tileSize; + dimY = 0; + for(int y = 0; y < counter; y++) + { + dimY += tileSize; + + // init mdd + RasGMArray myMDD2 = new RasGMArray(new RasMInterval("[" + String.valueOf(dimX-tileSize) + ":" + String.valueOf(dimX-1) + "," + + String.valueOf(dimY-tileSize) + ":" + String.valueOf(dimY-1) + "]"),1); + cells = tileSize*tileSize; + byte[] mydata2 = new byte[cells]; + for(int i = 0; i < cells; i++) + mydata2[i]=0; + myMDD2.setArray(mydata2); + myMDD2.setObjectTypeName("GreyImage"); + + // prepare query + myQuery = myApp.newOQLQuery(); + if(first) + { + myQuery.create("insert into $1 values $2"); + first = false; + } + else + myQuery.create("update $1 AS img SET img ASSIGN $2"); + myQuery.bind(collectionName); + myQuery.bind(myMDD2); + + // execute query + System.err.println("Inserting tile " + myMDD2.spatialDomain()); + myQuery.execute(); + finished += 1; + + // commit? + if(finished == commitInterval) + { + myta.commit(); + System.err.println("... committed, begin new transaction ..."); + myta = myApp.newTransaction(); + myta.begin(); + finished = 1; + } + + } + // now write the rest of y if there is something left: + if(dimY < overallSize-1) + { + RasGMArray myMDD3 = new RasGMArray(new RasMInterval("[" + String.valueOf(dimX-tileSize) + ":" + String.valueOf(dimX-1) + "," + + String.valueOf(dimY) + ":" + String.valueOf(overallSize-1) + "]"),1); + cells = tileSize*(overallSize-dimY); + byte[] mydata3 = new byte[cells]; + for(int i = 0; i < cells; i++) + mydata3[i]=0; + myMDD3.setArray(mydata3); + myMDD3.setObjectTypeName("GreyImage"); + + // prepare query + myQuery = myApp.newOQLQuery(); + if(first) + { + myQuery.create("insert into $1 values $2"); + first = false; + } + else + myQuery.create("update $1 AS img SET img ASSIGN $2"); + myQuery.bind(collectionName); + myQuery.bind(myMDD3); + + // execute query + System.err.println("Inserting tile " + myMDD3.spatialDomain()); + myQuery.execute(); + finished += 1; + + // commit? + if(finished == commitInterval) + { + myta.commit(); + System.err.println("... committed, begin new transaction ..."); + myta = myApp.newTransaction(); + myta.begin(); + finished = 1; + } + } + } + + // now write the rest of x if there is something left + dimY = 0; + if(dimX < overallSize-1) + { + for(int y = 0; y < counter; y++) + { + dimY += tileSize; + + // init mdd + RasGMArray myMDD4 = new RasGMArray(new RasMInterval("[" + String.valueOf(dimX) + ":" + String.valueOf(overallSize-1) + "," + + String.valueOf(dimY-tileSize) + ":" + String.valueOf(dimY-1) + "]"),1); + cells = (overallSize-dimX)*tileSize; + byte[] mydata4 = new byte[cells]; + for(int i = 0; i < cells; i++) + mydata4[i]=0; + myMDD4.setArray(mydata4); + myMDD4.setObjectTypeName("GreyImage"); + + // prepare query + myQuery = myApp.newOQLQuery(); + if(first) + { + myQuery.create("insert into $1 values $2"); + first = false; + } + else + myQuery.create("update $1 AS img SET img ASSIGN $2"); + myQuery.bind(collectionName); + myQuery.bind(myMDD4); + + // execute query + System.err.println("Inserting tile " + myMDD4.spatialDomain()); + myQuery.execute(); + finished += 1; + + // commit? + if(finished == commitInterval) + { + myta.commit(); + System.err.println("... committed, begin new transaction ..."); + myta = myApp.newTransaction(); + myta.begin(); + finished = 1; + } + } + + // now write the rest of y if available + if(dimY < overallSize-1) + { + RasGMArray myMDD5 = new RasGMArray(new RasMInterval("[" + String.valueOf(dimX) + ":" + String.valueOf(overallSize-1) + "," + + String.valueOf(dimY) + ":" + String.valueOf(overallSize-1) + "]"),1); + cells = (overallSize-dimX)*(overallSize-dimY); + byte[] mydata5 = new byte[cells]; + for(int i = 0; i < cells; i++) + mydata5[i]=0; + myMDD5.setArray(mydata5); + myMDD5.setObjectTypeName("GreyImage"); + + // prepare query + myQuery = myApp.newOQLQuery(); + if(first) + { + myQuery.create("insert into $1 values $2"); + first = false; + } + else + myQuery.create("update $1 AS img SET img ASSIGN $2"); + myQuery.bind(collectionName); + myQuery.bind(myMDD5); + + // execute query + System.err.println("Inserting tile " + myMDD5.spatialDomain()); + myQuery.execute(); + finished += 1; + } + } + + // READY! + myta.commit(); + System.err.println("FINISHED!"); + + + // drop test collection + myta = myApp.newTransaction(); + myta.begin(); + System.err.println("Drop test collection ..."); + myQuery = myApp.newOQLQuery(); + myQuery.create("drop collection $1"); + myQuery.bind(collectionName); + myQuery.execute(); + System.err.println(" ok."); + myta.commit(); + myta = myApp.newTransaction(); + myta.commit(); + + + + } + + catch ( Exception e ) { + System.out.println("ERROR: "); + System.out.println(e.getMessage()); + + if(myta.isOpen()) + { + System.err.println("Abort transaction ..."); + myta.abort(); + } + System.err.println("Close database ..."); + try { + mydb.close(); + System.err.println(" ok."); + } + catch ( Exception e2 ) { + } + System.err.println("Exiting..."); + System.exit(-1); + } + } + +} + + + diff --git a/java/rasj/test/Systemtest_rasj.java b/java/rasj/test/Systemtest_rasj.java new file mode 100644 index 0000000..50c33c5 --- /dev/null +++ b/java/rasj/test/Systemtest_rasj.java @@ -0,0 +1,295 @@ +package rasj.test; + +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/** *********************************************************** + * <pre> + * + * PURPOSE: + * + * + * + * COMMENTS: + * + * </pre> + *********************************************************** */ + +import java.io.*; + +import rasj.*; +import rasj.global.*; +import org.odmg.*; + + +// auxiliary classes for exception testing +class TestRasResultIsNoCellException extends RasResultIsNoCellException +{ + TestRasResultIsNoCellException() + { + super(); + } +} + +class TestRasResultIsNoIntervalException extends RasResultIsNoIntervalException +{ + TestRasResultIsNoIntervalException() + { + super(); + } +} + +class TestRasClientInternalException extends RasClientInternalException +{ + TestRasClientInternalException(String msg) + { + super("Systemtest_rasj","TestExceptions",msg); + } +} + +// main program +/** + * class for testing rasj interface + * @version $$ + */ +public class Systemtest_rasj +{ + +public static void main(String[] args) + { + String server = null; + String port = "7001"; + boolean wrongUsage = false; + + // get args + if(args.length == 0) + wrongUsage = true; + for(int i = 0; i < args.length; i+=2) + { + if (args[i].equals("-server")) + server = args[i+1]; + else if (args[i].equals("-port")) + port = args[i+1]; + else + wrongUsage = true; + } + + if(wrongUsage) + { + System.err.println("Usage: Systemtest_rasj -s <servername> [ -p <port> ]"); + System.exit(-1); + } + + // start + Implementation myApp = new RasImplementation("http://" + server + ":" + port); + + testExceptions(myApp); + + testMArrays marrayTest = new testMArrays(server); + + testIntervals intervalTest = new testIntervals(); + + } + + // exception testing + static void testExceptions(Implementation imp) + { + + boolean resultIsOk = false; + Database myDb = null; + Transaction myTa = null; + OQLQuery myQu = null; + + System.err.println("\n### Testing exceptions:"); + + // RasConnectionFailedException + Implementation errorApp; + String logMsg; + try { + errorApp = new RasImplementation("wrongserver:8080"); + myDb = errorApp.newDatabase(); + logMsg = "Exception was not thrown"; + myDb.open("RASBASE",Database.OPEN_READ_WRITE); + } + catch(RasConnectionFailedException e1) { + resultIsOk = true; + logMsg = e1.getMessage(); + } + catch(ODMGException e2) { + logMsg = e2.getMessage(); + } + log("RasConnectionFailedException",resultIsOk,logMsg); + + // RasDimensionMismatchException + resultIsOk = false; + logMsg = "Exception was not thrown"; + try { + RasMInterval test1; + RasMInterval test2 = new RasMInterval("[1:20,1:20]"); + RasMInterval test3 = new RasMInterval("[1:4,1:9,1:6]"); + + test1 = test2.intersectionWith(test3); + } + catch(RasDimensionMismatchException e1) { + resultIsOk = true; + logMsg = e1.getMessage(); + } + catch(Exception e2) { + logMsg = e2.getClass().getName() + ", " + e2.getMessage(); + } + log("RasDimensionMismatchException",resultIsOk,logMsg); + + // RasIndexOutOfBoundsException + resultIsOk = false; + logMsg = "Exception was not thrown"; + try { + RasGMArray myMDD = new RasGMArray(new RasMInterval("[1:5,1:5]"),1); + byte[] retVal = myMDD.getCell(new RasPoint(4,7)); + } + catch(RasIndexOutOfBoundsException e1) { + resultIsOk = true; + logMsg = e1.getMessage(); + } + catch(RasResultIsNoIntervalException e2) { + //this cannot occur + } + catch(RasDimensionMismatchException e3) { + // this cannot occur + } + log("RasIndexOutOfBoundsException",resultIsOk,logMsg); + + // RasClientInternalException + resultIsOk = false; + logMsg = "Exception was not thrown"; + try { + throw new TestRasClientInternalException("This is a test error"); + } + catch(RasClientInternalException e1) { + resultIsOk = true; + logMsg = e1.getMessage(); + } + log("RasClientInternalException",resultIsOk,logMsg); + + // RasResultIsNoCellException + resultIsOk = false; + logMsg = "Exception was not thrown"; + try { + throw new TestRasResultIsNoCellException(); + } + catch(RasResultIsNoCellException e1) { + resultIsOk = true; + logMsg = e1.getMessage(); + } + log("RasResultIsNoCellException",resultIsOk,logMsg); + + // RasResultIsNoIntervalException + resultIsOk = false; + logMsg = "Exception was not thrown"; + try { + throw new TestRasResultIsNoIntervalException(); + } + catch(RasResultIsNoIntervalException e1) { + resultIsOk = true; + logMsg = e1.getMessage(); + } + log("RasResultIsNoIntervalException",resultIsOk,logMsg); + + // RasStreamInputOverflowException + resultIsOk = false; + logMsg = "Exception was not thrown"; + try { + RasMInterval int1 = new RasMInterval(2); + int1.stream(new RasSInterval("1:10")); + int1.stream(new RasSInterval("1:5")); + int1.stream(new RasSInterval("1:20")); + } + catch(RasResultIsNoIntervalException e1) { + // + } + catch(RasStreamInputOverflowException e3) { + resultIsOk = true; + logMsg = e3.getMessage(); + } + log("RasStreamInputOverflowException",resultIsOk,logMsg); + + + // RasTypeInvalidException + resultIsOk = false; + logMsg = "Exception was not thrown"; + try { + RasPrimitiveType myType = new RasPrimitiveType("myType",RasGlobalDefs.RAS_BOOLEAN); + myType.getFloat(new Object()); + } + catch(RasTypeInvalidException e3) { + resultIsOk = true; + logMsg = e3.getMessage(); + } + log("RasTypeInvalidException",resultIsOk,logMsg); + + // RasTypeNotSupportedException + resultIsOk = false; + logMsg = "Exception was not thrown"; + try { + throw new RasTypeNotSupportedException("RAS_TEST"); + } + catch(RasTypeNotSupportedException e3) { + resultIsOk = true; + logMsg = e3.getMessage(); + } + log("RasTypeNotSupportedException",resultIsOk,logMsg); + } + + + + + + static void log(String testObject, boolean resultOK, String message) + { + if(resultOK) + System.err.println(testObject + " ... OK\n (" + message + ")"); + else + { + System.err.println(testObject + " ... FAILED!\n (" + message + ")"); + System.err.println("Continue? [y/n]"); + BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); + try { + String answer = br.readLine(); + while(answer != "") + { + if(answer.equals("n")) + System.exit(1); + else if(!answer.equals("y")) + { + System.err.println("Please answer y or n: "); + answer = br.readLine(); + } + } + } + catch(IOException e1) { + // + } + + } + } + + +} diff --git a/java/rasj/test/TestDbTa.java b/java/rasj/test/TestDbTa.java new file mode 100644 index 0000000..846e337 --- /dev/null +++ b/java/rasj/test/TestDbTa.java @@ -0,0 +1,549 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/** *********************************************************** + * <pre> + * + * PURPOSE: + * test rasj ODMG-level interface (database, TA, and basic query logic). + * TO BE DONE! + * + * PREREQUISITES: + * - Must have a database with at least one HTTP server running. + * - database must know basic types, in particular: GreySet. + * - login must allow read/write access to database + * + * + * COMMENTS: + * - testing philosophy is to run all tests and report. no exit code / exception + * is used for error indication; look into the output for ERROR_TAG instead. + * - unexpected exceptions are not caught, hence will make gmake fail and show the error + * - every test that fails must print a line containing ERROR_TAG + * </pre> + *********************************************************** */ + +import java.lang.Integer; +import org.odmg.*; +import rasj.*; +import rasj.odmg.*; + +public class TestDbTa + { + /** + * prefixes for test output + **/ + static final String PREFIX_PROGRAM = "+++ +++ +++ "; + static final String PREFIX_TESTSET = "+++ +++ "; + static final String PREFIX_TESTCASE = "+++ "; + + /** + * std error tag printed if a test fails + **/ + static final String ERROR_TAG = "ERROR: "; + + /** + * default values (override with cmd line option) + **/ + static final String DEFAULT_HOST = "localhost"; + static final int DEFAULT_PORT = 7001; + static final String DEFAULT_BASE = "RASBASE"; + static final String DEFAULT_USER = "rasguest"; + static final String DEFAULT_PASSWD = "rasguest"; + + /** + * global ODMG implementation object for use by all methods + **/ + static RasImplementation myApp = null; + + /** + * main program for testing + * on error, an exception is thrown (java main() knows no exit status) + **/ + public static void main(String argv[]) throws Exception + { + String serv = DEFAULT_HOST; + int port = DEFAULT_PORT; + String base = DEFAULT_BASE; + String user = DEFAULT_USER; + String passwd = DEFAULT_PASSWD; + boolean wrongUsage = false; // error in cmd line params? + + for (int i=argv.length-1; i>=0; i--) + { + if (argv[i].equals("--server")) + serv = argv[i+1]; + else if (argv[i].equals("--port")) + { + try + { + port = Integer.parseInt(argv[i+1]); + } + catch(Exception e) + { + wrongUsage = true; + } + } + else if (argv[i].equals("--database")) + base = argv[i+1]; + else if (argv[i].equals("--user")) + user = argv[i+1]; + else if (argv[i].equals("--passwd")) + passwd = argv[i+1]; + } + + if (wrongUsage) + { + System.out.println( "Usage: TestDbTa [--server s] [--port p] [--database d] [--user u] [--passwd p]" ); + System.out.println( "defaults: server=" + DEFAULT_HOST + ", port=" + DEFAULT_PORT + ", database=" + DEFAULT_BASE + ", user=" + DEFAULT_USER + ", passwd=" + DEFAULT_PASSWD ); + System.exit(-1); + } + + System.out.println( "rasdaman system test v5.1revC: testing class ODMG logic." ); + System.out.println( PREFIX_PROGRAM + "system test started, using server " + serv + ", port " + port + ", database " + base + ", user=" + user + ", passwd=" + passwd ); + + myApp = new RasImplementation( "http://" + serv + ":" + port ); + myApp.setUserIdentification(user, passwd); + + // -- START test cases ------------------------------------------------- + testDatabase( myApp, base ); + testTransaction( myApp, base ); + testAccessMode( myApp, base ); + // -- END test cases --------------------------------------------------- + + System.out.println( PREFIX_PROGRAM + "system test done." ); + return; + } // main() + + /** + * test database open/close + * any eventual exception that is not caught here is an error, and will cause an abort + **/ + static void testDatabase( RasImplementation myApp, String database ) + // throws RasDimensionMismatchException, RasIndexOutOfBoundsException + { + Database myDb = null; + System.out.println( PREFIX_TESTSET + "testing database open/close started." ); + + System.out.print( PREFIX_TESTCASE + "open db, null name..." ); + try + { + myDb = myApp.newDatabase(); + myDb.open( null, Database.OPEN_READ_ONLY ); + System.out.println( ERROR_TAG + "does not catch this." ); + } + catch(Exception e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + // FIXME: PB6: inappropriate error message + System.out.print( PREFIX_TESTCASE + "open db, empty name..." ); + try + { + myDb = myApp.newDatabase(); + myDb.open( "", Database.OPEN_READ_ONLY ); + System.out.println( ERROR_TAG + "does not catch this." ); + } + catch(Exception e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "open db, nonexisting db..." ); + try + { + myDb = myApp.newDatabase(); + myDb.open( "NO_SUCH_DATABASE", Database.OPEN_READ_ONLY ); + System.out.println( ERROR_TAG + "does not catch this." ); + } + catch(Exception e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + // FIXME: PB6: inappropriate error message + // System.out.print( PREFIX_TESTCASE + "open db, negative accessMode value..." ); + // try + // { + // myDb = myApp.newDatabase(); + // myDb.open( database, -1 ); + // System.out.println( ERROR_TAG + "does not catch this." ); + // } + // catch(Exception e) + // { + // System.out.println( "OK, recognized: " + e.getMessage() ); + // } + + // FIXME: PB6: inappropriate error message + // System.out.print( PREFIX_TESTCASE + "open db, illegal accessMode..." ); + // try + // { + // myDb = myApp.newDatabase(); + // myDb.open( "NO_SUCH_DATABASE", 100 ); + // System.out.println( ERROR_TAG + "does not catch this." ); + // } + // catch(Exception e) + // { + // System.out.println( "OK, recognized: " + e.getMessage() ); + // } + + System.out.print( PREFIX_TESTCASE + "open db, good call..." ); + try + { + myDb = myApp.newDatabase(); + myDb.open( database, Database.OPEN_READ_ONLY ); + Transaction myTa = myApp.newTransaction(); + myTa.begin(); + myTa.abort(); + System.out.println( "OK, tested through beginTA." ); + } + catch(Exception e) + { + System.out.println( ERROR_TAG + "good call does not open db: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "close previously opened db..." ); + try + { + myDb.close(); + System.out.println( "OK." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "can we open a transaction after closing db..." ); + try + { + Transaction myTa = myApp.newTransaction(); + myTa.begin(); + System.out.println( ERROR_TAG + "unfortunately yes." ); + } + catch(Exception e) + { + System.out.println( "OK, we can't." ); + } + + System.out.print( PREFIX_TESTCASE + "close db already closed..." ); + try + { + myDb.close(); + System.out.println( ERROR_TAG + "repeated close possible, alas." ); + } + catch (Exception e) + { + System.out.println( "OK." ); + } + + System.out.println( PREFIX_TESTSET + "testing database open/close done.\n" ); + return; + } // testDatabase() + + /** + * test transaction open/close + * any eventual exception that is not caught here is an error, and will cause an abort + **/ + static void testTransaction( RasImplementation myApp, String database ) throws ODMGException + { + Database myDb = null; + Transaction myTa = null; + System.out.println( PREFIX_TESTSET + "testing transaction start." ); + + System.out.print( PREFIX_TESTCASE + "isOpen on open DB, closed TA..." ); + try + { + myDb = myApp.newDatabase(); + myDb.open( database, Database.OPEN_READ_ONLY ); + myTa = myApp.newTransaction(); + if ( myTa.isOpen() ) + System.out.println( ERROR_TAG + "TA open on closed DB." ); + else + System.out.println( "OK, is not open." ); + } + catch (Exception e) + { + System.out.println( "OK: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "isOpen on open DB/TA..." ); + try + { + myTa.begin(); + if ( myTa.isOpen() ) + System.out.println( "OK, is open." ); + else + System.out.println( ERROR_TAG + "TA not open after opening." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "sending query to check open TA..." ); + try + { + OQLQuery myQu = myApp.newOQLQuery(); + myQu.create( "select r from RAS_COLLECTIONNAMES as r" ); + DBag result = (DBag) myQu.execute(); + if ( result == null ) + System.out.println( ERROR_TAG + "standard query failed." ); + else + System.out.println( "OK, query done." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "open TA on an already open TA..." ); + try + { + myTa.begin(); + if ( myTa.isOpen() ) + System.out.println( "OK, should remain open." ); + else + System.out.println( ERROR_TAG + "TA not open after 2nd opening." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "abort TA..." ); + try + { + myTa.abort(); + if ( myTa.isOpen() ) + System.out.println( ERROR_TAG + "TA open after abort." ); + else + System.out.println( "OK, is not open." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "query on aborted TA..." ); + try + { + OQLQuery myQu = myApp.newOQLQuery(); + myQu.create( "select r from RAS_COLLECTIONNAMES as r" ); + DBag result = (DBag) myQu.execute(); + if ( result == null ) + System.out.println( "OK, standard query failed." ); + else + System.out.println( ERROR_TAG + "query got through." ); + } + catch (Exception e) + { + System.out.println( "OK, failed: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "abort TA on aborted TA..." ); + try + { + myTa.abort(); + if ( myTa.isOpen() ) + System.out.println( ERROR_TAG + "TA open after abort." ); + else + System.out.println( "OK, is not open." ); + } + catch (Exception e) + { + System.out.println( "OK, noticed: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "open new TA, send query..." ); + try + { + myTa.begin(); + if ( ! myTa.isOpen() ) + System.out.println( ERROR_TAG + "TA not open." ); + else + { + OQLQuery myQu = myApp.newOQLQuery(); + myQu.create( "select r from RAS_COLLECTIONNAMES as r" ); + DBag result = (DBag) myQu.execute(); + if ( result == null ) + System.out.println( ERROR_TAG + "standard query failed." ); + else + System.out.println( "OK." ); + } + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "commit TA..." ); + try + { + myTa.commit(); + if ( myTa.isOpen() ) + System.out.println( "OK, closed now. " ); + else + System.out.println( ERROR_TAG + "TA still open. " ); + OQLQuery myQu = myApp.newOQLQuery(); + myQu.create( "select r from RAS_COLLECTIONNAMES as r" ); + DBag result = (DBag) myQu.execute(); + if ( result == null ) + System.out.println( "OK, query failed." ); + else + System.out.println( ERROR_TAG + "query got through." ); + } + catch (TransactionNotInProgressException e) + { + System.out.println( "...OK, query failed: " + e.getMessage() ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.println( PREFIX_TESTSET + "testing transaction done.\n" ); + return; + } // testTransaction() + + /** + * test access modes + * any eventual exception that is not caught here is an error, and will cause an abort + **/ + static void testAccessMode( RasImplementation myApp, String database ) + // throws RasDimensionMismatchException, RasIndexOutOfBoundsException + { + Database myDb = null; + Transaction myTa = null; + System.out.println( PREFIX_TESTSET + "testing accessMode start." ); + + System.out.print( PREFIX_TESTCASE + "open readonly, read query..." ); + try + { + myDb = myApp.newDatabase(); + myDb.open( database, Database.OPEN_READ_ONLY ); + myTa = myApp.newTransaction(); + myTa.begin(); + + OQLQuery myQu = myApp.newOQLQuery(); + myQu.create( "select r from RAS_COLLECTIONNAMES as r" ); + DBag result = (DBag) myQu.execute(); + if ( result == null ) + System.out.println( ERROR_TAG + "query failed." ); + else + System.out.println( "OK, query got through." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "open readonly, update query (create collection)..." ); + try + { + myDb = myApp.newDatabase(); + myDb.open( database, Database.OPEN_READ_ONLY ); + myTa = myApp.newTransaction(); + myTa.begin(); + + OQLQuery myQu = myApp.newOQLQuery(); + myQu.create( "create collection TestDbTa_collection GreySet" ); + DBag result = (DBag) myQu.execute(); + } + catch (DatabaseIsReadOnlyException e) + { + System.out.println( "OK, update failed." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "commit TA, close DB..." ); + try + { + myTa.commit(); + myDb.close(); + System.out.println( "OK." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "open DB readwrite, open TA, read query..." ); + try + { + myDb.open( database, Database.OPEN_READ_WRITE ); + myTa = myApp.newTransaction(); + myTa.begin(); + + OQLQuery myQu = myApp.newOQLQuery(); + myQu.create( "select r from RAS_COLLECTIONNAMES as r" ); + DBag result = (DBag) myQu.execute(); + if ( result == null ) + System.out.println( ERROR_TAG + "query failed." ); + else + System.out.println( "OK, query got through." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "update query (create & drop collection)..." ); + try + { + OQLQuery myQu = myApp.newOQLQuery(); + myQu.create( "create collection TestDbTa_collection GreySet" ); + DBag result = (DBag) myQu.execute(); + + // we want to see that a commit really preserves changes: + System.out.print( "re-opening TA..." ); + myTa.commit(); + myTa.begin(); + + myQu.create( "drop collection TestDbTa_collection" ); + result = (DBag) myQu.execute(); + System.out.println( "OK, query got through." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "commit TA, close DB..." ); + try + { + myTa.commit(); + myDb.close(); + System.out.println( "OK." ); + } + catch (Exception e) + { + System.out.println( ERROR_TAG + e.getMessage() ); + } + + System.out.println( PREFIX_TESTSET + "testing accessMode done.\n" ); + return; + } // testAccessMode() + + } // TestDbTa diff --git a/java/rasj/test/TestException.java b/java/rasj/test/TestException.java new file mode 100644 index 0000000..9cfe894 --- /dev/null +++ b/java/rasj/test/TestException.java @@ -0,0 +1,361 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/** *********************************************************** + * <pre> + * + * PURPOSE: + * exception testing (was: Systemtest_rasj). + * + * + * COMMENTS: + * + * </pre> + *********************************************************** */ + +import java.io.*; + +import rasj.*; +import rasj.global.*; +import org.odmg.*; + + +// auxiliary classes for exception testing +class TestRasResultIsNoCellException extends RasResultIsNoCellException + { + TestRasResultIsNoCellException() + { + super(); + } + } + +class TestRasResultIsNoIntervalException extends RasResultIsNoIntervalException + { + TestRasResultIsNoIntervalException() + { + super(); + } + } + +class TestRasClientInternalException extends RasClientInternalException + { + TestRasClientInternalException(String msg) + { + super("TestException","TestExceptions",msg); + } + } + +/** + * class for testing rasj interface + * @version $$ + */ +public class TestException + { + /** + * prefixes for test output + **/ + static final String PREFIX_PROGRAM = "+++ +++ +++ "; + static final String PREFIX_TESTSET = "+++ +++ "; + static final String PREFIX_TESTCASE = "+++ "; + + /** + * std error tag printed if a test fails + **/ + static final String ERROR_TAG = "ERROR: "; + + /** + * default values (override with cmd line option) + **/ + static final String DEFAULT_HOST = "localhost"; + static final int DEFAULT_PORT = 7001; + static final String DEFAULT_BASE = "RASBASE"; + static final String DEFAULT_USER = "rasguest"; + static final String DEFAULT_PASSWD = "rasguest"; + + // main program + public static void main(String[] args) throws Exception + { + String server = DEFAULT_HOST; + int port = DEFAULT_PORT; + String base = DEFAULT_BASE; + String user = DEFAULT_USER; + String passwd = DEFAULT_PASSWD; + boolean wrongUsage = false; + + // get args + if(args.length == 0) + wrongUsage = true; + for(int i = 0; i < args.length; i+=2) + { + if (args[i].equals("--server")) + server = args[i+1]; + else if (args[i].equals("--port")) + { + try + { + port = Integer.parseInt(args[i+1]); + } + catch(Exception e) + { + wrongUsage = true; + } + } + else if (args[i].equals("--database")) + base = args[i+1]; + else if (args[i].equals("--user")) + user = args[i+1]; + else if (args[i].equals("--passwd")) + passwd = args[i+1]; + } + + if(wrongUsage) + { + System.err.println("Usage: TestException [--server s] [--port p] [--database d]"); + System.out.println( "defaults: server=" + DEFAULT_HOST + ", port=" + DEFAULT_PORT + ", database=" + DEFAULT_BASE ++ ", user=" + DEFAULT_USER + ", passwd=" + DEFAULT_PASSWD ); + System.exit(-1); + } + + + + System.out.println( "rasdaman system test v5.1revC: testing exceptions." ); + System.out.println( PREFIX_PROGRAM + "system test started, using server " + server + ", port " + port + ", database " + base + ", user=" + user + ", passwd=" + passwd ); + + // Implementation myApp = new RasImplementation("http://" + server + ":" + port); + RasImplementation myApp = new RasImplementation( "http://" + server + ":" + port ); + myApp.setUserIdentification(user, passwd); + + // -- START test cases ------------------------------------------------- + testExceptions( myApp, base ); + // -- END test cases --------------------------------------------------- + + System.out.println( PREFIX_PROGRAM + "system test done." ); + return; + } // main() + + /** + * test exceptions + * any eventual exception that is not caught here is an error, and will cause an abort + **/ + static void testExceptions( RasImplementation imp, String database ) throws Exception + { + boolean resultIsOk = false; + Database myDb = null; + Transaction myTa = null; + OQLQuery myQu = null; + + System.out.println( PREFIX_TESTSET + "testing exceptions started." ); + + System.out.print( PREFIX_TESTCASE + "provoking RasConnectionFailedException..." ); + RasImplementation errorApp; + String logMsg; + try + { + errorApp = new RasImplementation("wrongserver:8080"); + myDb = errorApp.newDatabase(); + myDb.open( database, Database.OPEN_READ_WRITE ); + System.out.println( ERROR_TAG + "does not catch this." ); + myDb.close(); + } + catch(RasConnectionFailedException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasDimensionMismatchException..." ); + try + { + RasMInterval test1; + RasMInterval test2 = new RasMInterval("[1:20,1:20]"); + RasMInterval test3 = new RasMInterval("[1:4,1:9,1:6]"); + test1 = test2.intersectionWith(test3); + System.out.println( ERROR_TAG + "does not catch this." ); + } + catch(RasDimensionMismatchException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasIndexOutOfBoundsException..." ); + try + { + RasGMArray myMDD = new RasGMArray(new RasMInterval("[1:5,1:5]"),1); + byte[] retVal = myMDD.getCell(new RasPoint(4,7)); + System.out.println( ERROR_TAG + "does not catch this." ); + } + catch(RasIndexOutOfBoundsException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasClientInternalException (via subclassed e.)..." ); + try + { + throw new TestRasClientInternalException("This is a test error"); + } + catch(RasClientInternalException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasResultIsNoCellException (via subclassed e.)..." ); + try + { + throw new TestRasResultIsNoCellException(); + } + catch(RasResultIsNoCellException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasResultIsNoIntervalException (via subclassed e.)..." ); + try + { + throw new TestRasResultIsNoIntervalException(); + } + catch(RasResultIsNoIntervalException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasStreamInputOverflowException..." ); + try + { + RasMInterval int1 = new RasMInterval(2); + int1.stream(new RasSInterval("1:10")); + int1.stream(new RasSInterval("1:5")); + int1.stream(new RasSInterval("1:20")); + System.out.println( ERROR_TAG + "does not catch this." ); + } + catch(RasStreamInputOverflowException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasTypeInvalidException..." ); + try + { + RasPrimitiveType myType = new RasPrimitiveType("myPrivateType",RasGlobalDefs.RAS_BOOLEAN); + myType.getFloat(new Object()); + System.out.println( ERROR_TAG + "does not catch this." ); + } + catch(RasTypeInvalidException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasTypeNotSupportedException..." ); + try + { + throw new RasTypeNotSupportedException("test"); + } + catch(RasTypeNotSupportedException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasIllegalULongValueException (faked)..." ); + try + { + throw new RasIllegalULongValueException( 42 ); + } + catch(RasIllegalULongValueException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasIllegalUShortValueException (faked)..." ); + try + { + throw new RasIllegalUShortValueException( 42 ); + } + catch(RasIllegalUShortValueException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasInvalidNameException (illegal chars in obj type name)..." ); + try + { + RasGMArray myMDD = new RasGMArray(new RasMInterval("[1:400,1:400]"),1); + myMDD.setObjectTypeName("_!_$_%_&_ _"); + System.out.println( ERROR_TAG + "does not catch this." ); + } + catch(RasInvalidNameException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + // FIXME: PB9 + System.out.print( PREFIX_TESTCASE + "provoking RasInvalidNameException (name too long)..." ); + try + { + RasGMArray myMDD = new RasGMArray(new RasMInterval("[1:400,1:400]"),1); + myMDD.setObjectTypeName("loooongname__1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_1234567890_" ); + System.out.println( ERROR_TAG + "does not catch this." ); + } + catch(RasInvalidNameException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "provoking RasQueryExecutionFailedException..." ); + try + { + // Database myDb2 = imp.newDatabase(); + // myDb2.open( database, Database.OPEN_READ_ONLY ); + // Transaction myTa2 = imp.newTransaction(); + // myTa2.begin(); + + // OQLQuery myQu2 = imp.newOQLQuery(); + // myQu2.create( "select r r from RAS_COLLECTIONNAMES as r" ); + // DBag result = (DBag) myQu2.execute(); + + // myTa2.abort(); + // myDb2.close(); + System.out.print( "this is meant for a severe internal problem which I cannot provoke; will fake..." ); + throw new RasQueryExecutionFailedException( 1, 2, 3, "(fake)" ); + } + catch(RasQueryExecutionFailedException e) + { + System.out.println( "OK, recognized: " + e.getMessage() ); + } + + // protected exception in rasj, not accessible + // System.out.print( PREFIX_TESTCASE + "provoking RasTypeUnknownException..." ); + // try + // { + // // RasGMArray myMDD = new RasGMArray(new RasMInterval("[1:400,1:400]"),1); + // // myMDD.setObjectTypeName( "charrrrr" ); + // System.out.print( "superseded by RasTypeNotSupportedException - cannot catch it; will fake..." ); + // throw new RasTypeUnknownException("test"); + // } + // catch(RasTypeUnknownException e) + // { + // System.out.println( "OK, recognized: " + e.getMessage() ); + // } + + System.out.println( PREFIX_TESTSET + "testing exceptions done." ); + return; + } // testExceptions() + + } // TestException diff --git a/java/rasj/test/TestHttp.java b/java/rasj/test/TestHttp.java new file mode 100644 index 0000000..aca0e40 --- /dev/null +++ b/java/rasj/test/TestHttp.java @@ -0,0 +1,642 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/************************************************************* + * <pre> + * + * PURPOSE: + * + * + * COMMENTS: + * - not part of the standard systemtest, because it does not use std + * interface but copies internal ras/clientcomm code + * </pre> + *********************************************************** */ + +import rasj.*; +import rasj.odmg.*; +import org.odmg.*; +import rasj.global.*; + +import java.io.*; +import java.util.*; + +import java.lang.*; +import java.net.*; + +/** + * This class handles a HTTP-request to the RasDaMan server. + * The specified RasDaMan server is contacted, the specified command is sent to + * the server, and the result of the query is retrieved and stored in a byte array. + * The specification of the communication protocol is given below. + * <P> + * + * @version $Revision: 1.1 $ + */ + +public class TestHttp implements RasCommDefs, RasGlobalDefs +{ + + static final String rcsid = "@(#)Package rasj.test, class TestHttp: $Header: /home/rasdev/CVS-repository/rasdaman/java/rasj/test/TestHttp.java,v 1.1 2003/12/19 16:05:43 rasdev Exp $"; + + +/** + * The type of this client + */ + private String client = "RASCLIENT"; + +/** + * The result type ( MDD Collection, Skalar Collection, Error, Integer ). This field is set + * automatically when a query has been executed, so there's no setResultType method. + */ + private static byte resultType = 0; + +/** + * The result of the query +**/ + private static Object result = null; + + +/** + * This method sends a query to the RasDaMan Server and retrieves the results. + * + * @param con server connection + * @param parameters the parameters for the request as name/value pairs (for example "clientID=4354351&queryString=select img from test") + */ + public static void execute( String serverURL, String parameters ) + throws RasQueryExecutionFailedException, RasConnectionFailedException + { + System.out.println( "RasHttpRequest.execute: start. parameters=" + parameters ); + + BenchmarkTimer httpTimer = new BenchmarkTimer("httpRequest direct"); + BenchmarkTimer rcvTimer = new BenchmarkTimer("receive direct"); + + try + { + URL url = new URL( serverURL ); + + System.out.println( "RasHttpRequest.execute: sending to " + url + " POST request=" + parameters ); + + httpTimer.startTimer(); + + BenchmarkTimer sendTimer = new BenchmarkTimer("send direct"); + sendTimer.startTimer(); + + // Send the query + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestProperty("Content-type","application/octet-stream"); + con.setRequestProperty("User-Agent","RasDaMan Java Client"); + con.setRequestProperty("Version","1.0"); + con.setRequestMethod("POST"); + con.setDoInput(true); + con.setDoOutput(true); + con.setUseCaches(false); + + OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream(),"8859_1"); + out.write(parameters,0,parameters.length()); + out.flush(); + out.close(); + + sendTimer.stopTimer(); + sendTimer.print(); + + rcvTimer.startTimer(); + + // Read response + BenchmarkTimer getInputTimer = new BenchmarkTimer("getInputStream direct"); + getInputTimer.startTimer(); + DataInputStream in = new DataInputStream(con.getInputStream()); + System.out.println("RasHttpRequest.execute: received " + in ); + getInputTimer.stopTimer(); + getInputTimer.print(); + + // read binData + // binData = new byte[dataSize]; + // readBytes = 0; + // readBytesTmp = 0; + // while( (readBytesTmp != -1) && (readBytes < dataSize) ) + // { + // readBytesTmp = in.read(binData,readBytes,dataSize-readBytes); + // readBytes += readBytesTmp; + // System.out.println("Read " + readBytesTmp +" Bytes:" + binData); + // } + // in.close(); + // con.disconnect(); + + /* variables for later use */ + byte[] b1 = new byte[1]; + byte[] b4 = new byte[4]; + byte endianess = 0; + String collType = null; + int numberOfResults = 0; + int dataSize = 0; + byte[] binData = null; + int readBytes = 0; + int readBytesTmp = 0; + DBag resultBag; + RasGMArray res = null; + + in.read(b1); + + resultType = b1[0]; + Debug.talkVerbose("RasHttpRequest.execute: resultType=" + resultType ); + switch( resultType ) + { + case RESPONSE_OK: + case RESPONSE_OK_NEGATIVE: + //Nothing todo + break; + + // +++++++++++++++++++++++++++++++++++++++++++++++++ + case RESPONSE_MDDS: + Debug.talkVerbose("RasHttpRequest.execute: result type is MDD." ); + // read Endianess + while(in.read(b1) == 0) + ; + endianess = b1[0]; + + // read Collection Type + collType = RasUtils.readString(in); + Debug.talkVerbose("RasHttpRequest.execute: colltype=" + collType); + + // read NumberOfResults + while(in.available() < 4) + ; + in.read(b4); + numberOfResults = RasUtils.ubytesToInt(b4,endianess); + Debug.talkVerbose("RasHttpRequest.execute: number of results: " + numberOfResults); + + // Initialize return-set and parameters + resultBag = new RasBag(); + String mddBaseType = null; + String domain = null; + String oid = ""; + RasOID roid = null; + + // do this for each result + for(int x = 0; x < numberOfResults; x++) + { + Debug.talkVerbose("RasHttpRequest.execute: handling result #" + (x+1) ); + //read mddBaseType + mddBaseType = RasUtils.readString(in); + + // read spatialDomain + domain = RasUtils.readString(in); + + // read OID + oid = RasUtils.readString(in); + //System.err.println("OID is " + oid); + roid = new RasOID(oid); + + // read size of binData + while(in.available() < 4) + ; + in.read(b4); + + dataSize = RasUtils.ubytesToInt(b4,endianess); + + Debug.talkVerbose("RasHttpRequest.execute: mddBaseType is " + mddBaseType + ", spatialDomain=" + domain + ", size of BinData=" + dataSize ); + + // read binData + binData = new byte[dataSize]; + readBytes = 0; + readBytesTmp = 0; + + while( (readBytesTmp != -1) && (readBytes < dataSize) ) + { + readBytesTmp = in.read(binData,readBytes,dataSize-readBytes); + readBytes += readBytesTmp; + } + + Debug.talkVerbose("RasHttpRequest.execute: read " + readBytes + " bytes."); + + RasType rType = RasType.getAnyType(mddBaseType); + //System.out.println(rType); + RasBaseType rb = null; + + if(rType.getClass().getName().equals("rasj.RasMArrayType")) + { + RasMArrayType tmp = (RasMArrayType)rType; + rb = tmp.getBaseType(); + } + else + { + Debug.talkCritical("RasHttpRequest.execute: exception: element of MDD Collection is no MArray" ); + throw new RasClientInternalException("RasHttpRequest","execute()","element of MDD Collection is no MArray"); + } + + if(rb.isBaseType()) + { + if(rb.isStructType()) + { + // It is a structType + //System.err.println("It is a structType"); + RasStructureType sType = (RasStructureType)rb; + //System.out.println(sType); + res = new RasGMArray(new RasMInterval(domain), 0); + res.setTypeLength(rb.getSize()); + res.setArraySize(dataSize); + res.setArray(binData); + //insert into result set + resultBag.add(res); + break; + + } else + { + // It is a primitiveType + RasPrimitiveType pType = (RasPrimitiveType)rb; + + //System.err.println("It's a primitive type: " + pType); + switch(pType.getTypeID()) + { + case RAS_BOOLEAN: + case RAS_BYTE: + case RAS_CHAR: + //System.err.println("It's a byte array!"); + res = new RasMArrayByte(new RasMInterval(domain)); + break; + case RAS_SHORT: + //System.err.println("It's a short array!"); + res = new RasMArrayShort(new RasMInterval(domain)); + break; + + case RAS_USHORT: + //System.err.println("It's a ushort array!"); + byte[] tmData = new byte[dataSize*2]; + for(int i=0;i<dataSize*2;) + { + tmData[i] = 0; + tmData[i+1] = 0; + tmData[i+2] = binData[i/2]; + tmData[i+3] = binData[i/2+1]; + i = i+SIZE_OF_INTEGER; + } + binData = tmData; + res = new RasMArrayInteger(new RasMInterval(domain)); + break; + + case RAS_INT: + case RAS_LONG: + //System.err.println("It's a integer array!"); + res = new RasMArrayInteger(new RasMInterval(domain)); + break; + case RAS_ULONG: + //System.err.println("It's a ulong array!"); + byte[] tmpData = new byte[dataSize*2]; + for(int i=0;i<dataSize*2;) + { + tmpData[i] = 0; + tmpData[i+1] = 0; + tmpData[i+2] = 0; + tmpData[i+3] = 0; + tmpData[i+4] = binData[i/2]; + tmpData[i+5] = binData[i/2+1]; + tmpData[i+6] = binData[i/2+2]; + tmpData[i+7] = binData[i/2+3]; + i = i+SIZE_OF_LONG; + } + binData = tmpData; + res = new RasMArrayLong(new RasMInterval(domain)); + break; + case RAS_FLOAT: + //System.err.println("It's a float array!"); + res = new RasMArrayFloat(new RasMInterval(domain)); + break; + case RAS_DOUBLE: + //System.err.println("It's a double array!"); + res = new RasMArrayDouble(new RasMInterval(domain)); + break; + default: + //System.err.println("It's a GMArray!"); + res = new RasGMArray(new RasMInterval(domain), pType.getSize()); + //throw new RasTypeNotSupportedException(pType.getName()); + } + // set array data + res.setArray(binData); + // set oid + res.setOID(roid); + //insert into result set + resultBag.add(res); + } + + } + else throw new RasClientInternalException("RasHttpRequest","execute()","Type of MDD is no Base Type"); + } + + result = resultBag; + + // close stream + in.close(); + + break; + + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + case RESPONSE_SKALARS: + //System.err.println("Skalar = 2"); + // read Endianess + while(in.read(b1) == 0); + endianess = b1[0]; + + // read Collection Type + collType = RasUtils.readString(in); + RasType rt = new RasType(); + try + { + rt = rt.getAnyType(collType); + //System.err.println("Colltype is " + rt); + } + catch(Exception e) + { + throw new RasTypeNotSupportedException(rt + " as RasCollectionType"); + } + if(rt.getTypeID()!=RasGlobalDefs.RAS_COLLECTION) + throw new RasTypeNotSupportedException(rt + " as RasCollectionType"); + + // read NumberOfResults + while(in.available() < 4); + in.read(b4); + numberOfResults = RasUtils.ubytesToInt(b4,endianess); + //System.err.println("Number of results: " + numberOfResults); + + // Initailize return-list + resultBag = new RasBag(); + + // do this for each result + for(int x = 0; x < numberOfResults; x++) + { + // read elementType + String elementType = RasUtils.readString(in); + RasType et = new RasType(); + et = ((RasCollectionType)rt).getElementType(); + //System.err.println("ElementType is " + et); + + // read size of binData + while(in.available() < 4); + in.read(b4); + dataSize = RasUtils.ubytesToInt(b4,endianess); + //System.err.print("Size of BinData: "); + //System.err.println(dataSize); + + // read binData + binData = new byte[dataSize]; + readBytes = 0; + readBytesTmp = 0; + while( (readBytesTmp != -1) && (readBytes < dataSize) ) + { + readBytesTmp = in.read(binData,readBytes,dataSize-readBytes); + readBytes += readBytesTmp; + /* + System.err.println("Read " + readBytesTmp +" Bytes (" + + readBytes + " Bytes overall)"); + */ + } + //System.err.println("Füge ein ..." + new String(binData)); + + ByteArrayInputStream bis = new ByteArrayInputStream(binData); + DataInputStream dis = new DataInputStream(bis); + // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + switch(et.getTypeID()) + { + case RasGlobalDefs.RAS_MINTERVAL: + resultBag.add(new RasMInterval(new String(binData))); + break; + case RasGlobalDefs.RAS_SINTERVAL: + resultBag.add(new RasSInterval(new String(binData))); + break; + case RasGlobalDefs.RAS_POINT: + resultBag.add(new RasPoint(new String(binData))); + break; + case RasGlobalDefs.RAS_OID: + resultBag.add(new RasOID(new String(binData))); + break; + case RAS_BOOLEAN: + case RAS_BYTE: + case RAS_CHAR: + byte b = binData[0]; + resultBag.add(new Byte(b)); + break; + case RAS_DOUBLE: + double d = dis.readDouble(); + resultBag.add(new Double(d)); + break; + case RAS_FLOAT: + float f = dis.readFloat(); + resultBag.add(new Float(f)); + break; + case RAS_ULONG: + byte[] bu = new byte[8]; + bu[0] = 0; + bu[1] = 0; + bu[2] = 0; + bu[3] = 0; + bu[4] = dis.readByte(); + bu[5] = dis.readByte(); + bu[6] = dis.readByte(); + bu[7] = dis.readByte(); + ByteArrayInputStream bis2 = new ByteArrayInputStream(bu); + DataInputStream dis2 = new DataInputStream(bis2); + long ul = dis2.readLong(); + resultBag.add(new Long(ul)); + break; + case RAS_LONG: + case RAS_INT: + int i = dis.readInt(); + resultBag.add(new Integer(i)); + break; + case RAS_USHORT: + int j = dis.readUnsignedShort(); + resultBag.add(new Integer(j)); + break; + case RAS_SHORT: + short s = dis.readShort(); + resultBag.add(new Short(s)); + break; + default: + throw new RasTypeNotSupportedException(et + " as ElementType "); + } + } + result = resultBag; + + // close stream + in.close(); + break; + + //++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + case RESPONSE_ERROR: + Debug.talkCritical("RasHttpRequest.execute: execution failed. Error = 0"); + + // read Endianess + while(in.read(b1) == 0) + ; + endianess = b1[0]; + + // read Error Number + while(in.available() < 4) + ; + in.read(b4); + int errNo = RasUtils.ubytesToInt(b4,endianess); + + // read Line Number + while(in.available() < 4) + ; + in.read(b4); + int lineNo = RasUtils.ubytesToInt(b4,endianess); + + // read Column Number + while(in.available() < 4) + ; + in.read(b4); + int colNo = RasUtils.ubytesToInt(b4,endianess); + + // read token + String token = RasUtils.readString(in); + + Debug.talkCritical("RasHttpRequest.execute: Errno=" + errNo + ", lineNo=" + lineNo + ", colNo=" + colNo + ", Token=" + token); + + throw new RasQueryExecutionFailedException(errNo,lineNo,colNo,token); + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + case RESPONSE_INT: + // read Integer Value + //System.err.println("Now reading integer value..."); + while(in.available() < 4); + in.read(b4); + result = new Integer(RasUtils.ubytesToInt(b4,endianess)); + //System.err.println("Int Value is : " + result.getInt()); + break; + + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + case RESPONSE_OID: + // read Values + String sys = RasUtils.readString(in); + String base = RasUtils.readString(in); + double d = in.readDouble(); + //System.out.println(sys+base+"localOID als double = " + d); + resultBag = new RasBag(); + resultBag.add(new RasOID(sys, base, d)); + result = resultBag; + // close stream + in.close(); + break; + default: + Debug.talkCritical( "RasHttpRequest.execute: illegal response type: " + resultType ); + break; + + } + + con.disconnect(); // close connection to server -- PB 2003-jun-15 + } + catch( MalformedURLException e ) + { + Debug.leaveCritical( "RasHttpRequest.execute: leave. malformed URL: " + e.getMessage() ); + throw new RasConnectionFailedException(MANAGER_CONN_FAILED, serverURL ); + } + catch( IOException e ) + { + Debug.leaveCritical( "RasHttpRequest.execute: leave. IO exception: " + e.getMessage() ); + throw new RasClientInternalException("RasHttpRequest","execute()",e.getMessage()); + } + catch( RasResultIsNoIntervalException e ) + { + Debug.leaveCritical( "RasHttpRequest.execute: leave. result no interval: " + e.getMessage() ); + throw new RasClientInternalException("RasHttpRequest","execute()",e.getMessage()); + } + + rcvTimer.stopTimer(); + rcvTimer.print(); + + httpTimer.stopTimer(); + httpTimer.print(); + + System.out.println( "RasHttpRequest.execute: leave. resultType=" + resultType ); + } // execute() + + public static void main( String[] args ) + { + String server = "localhost"; + String port = "7001"; + String base = "RASBASE"; + String user = "rasguest"; + String passwd = "rasguest"; + String query = "select r from RAS_COLLECTIONNAMES as r"; + int count = 1; + + System.out.println( "Query test started." ); + + for (int i=args.length-1; i>=0; i--) + { + if (args[i].equals("--server")) + server = args[i+1]; + if (args[i].equals("--port")) + port = args[i+1]; + if (args[i].equals("--database")) + base = args[i+1]; + if (args[i].equals("--user")) + user = args[i+1]; + if (args[i].equals("--passwd")) + passwd = args[i+1]; + if (args[i].equals("--query")) + query = args[i+1]; + if (args[i].equals("--count")) + count = Integer.parseInt(args[i+1]); + } + + try + { + RasImplementation myApp = new RasImplementation("http://"+server+":"+port); + myApp.setUserIdentification(user, passwd); + + System.out.println( "opening database..." ); + Database myDb = myApp.newDatabase(); + myDb.open( base, Database.OPEN_READ_ONLY ); + + System.out.println( "starting transaction..." ); + Transaction myTa = myApp.newTransaction(); + myTa.begin(); + + String parameters = "Command=8&ClientID=1&QueryString=" + query; + String serverUrl = "http://" + server + ":" + 7102; // port; + + for (int i = 0; i < count; i++) + { + System.out.println( "sending query #" + i + "..." ); + execute( serverUrl, parameters ); + } + + System.out.println( "closing transaction..." ); + myTa.abort(); + + System.out.println( "closing database..." ); + myDb.close(); + System.out.println( "all done." ); + + } + catch(Exception e) + { + System.err.println( e.getMessage() ); + } + + System.out.println( "Query test done." ); + + } // main() + +} // TestHttp + diff --git a/java/rasj/test/TestMArray.java b/java/rasj/test/TestMArray.java new file mode 100644 index 0000000..e8f817f --- /dev/null +++ b/java/rasj/test/TestMArray.java @@ -0,0 +1,904 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/** *********************************************************** + * <pre> + * + * PURPOSE: class for testing special MArrays + * + * + * COMMENTS: + * - adapt to general testbed structure + * </pre> + *********************************************************** */ + +import java.io.*; +import java.net.*; +import rasj.clientcommhttp.*; +import rasj.odmg.*; +import org.odmg.*; +import rasj.*; +import java.util.*; + +/** + * class for testing special MArrays + * for testing please enable test data output in toString method of RASGMArray + * @version $$ + */ +public class TestMArray +{ + /** + * constants used in this test + **/ + // prefixes for test output + static final String PREFIX_PROGRAM = "+++ +++ +++ "; + static final String PREFIX_TESTSET = "+++ +++ "; + static final String PREFIX_TESTCASE = "+++ "; + + static final String DEFAULT_HOST = "localhost"; + static final String DEFAULT_BASE = "RASBASE"; + static final String DEFAULT_COLL = "test"; + /** + * std error tag printed if a test fails + **/ + static final String ERROR_TAG = "ERROR: "; + + /** + * main program for testing + * on error, an exception is thrown (java main() knows no exit status) + **/ + public static void main(String[] args) + { + String serv = DEFAULT_HOST; + String base = DEFAULT_BASE; + String coll = DEFAULT_COLL; + boolean wrongUsage = false; // error in cmd line params? + + for (int i=args.length-1; i>=0; i--) + { + if (args[i].equals("--server")) + serv = args[i+1]; + else if (args[i].equals("--database")) + base = args[i+1]; + else if (args[i].equals("--collname")) + coll = args[i+1]; + else + wrongUsage = true; + } + + if (wrongUsage) + { + System.out.println( "Usage: TestMArray [--server s] [--database d] [--collname c]" ); + System.out.println( "defaults: s=" + DEFAULT_HOST + ", d=" + DEFAULT_BASE + ", c=" + DEFAULT_COLL ); + return; + } + + System.out.println( "rasdaman system test v5.1revC: testing class MArray." ); + System.out.println( PREFIX_PROGRAM + "system test started, using server" + serv + ", database " + base + ", collection" + coll ); + + // -- START test cases ------------------------------------------------- + TestMArray marrayTest = new TestMArray(serv); + // -- END test cases --------------------------------------------------- + + System.out.println( PREFIX_PROGRAM + "system test done." ); + return; + } // main() + + public TestMArray(String server) + { + DBag resultBag = null; + Object result = null; + Transaction myTa = null; + Database myDb = null; + OQLQuery myQu = null; + + boolean equal = false; + + try + { + System.out.println("### Testing MArrays: ..."); + Implementation myApp = new RasImplementation("http://"+server+":7001"); + myDb = myApp.newDatabase(); + + System.out.println("Opening database ..."); + myDb.open("RASBASE", Database.OPEN_READ_WRITE); + myTa = myApp.newTransaction(); + + int width, height, len; + width = 18; + height = 18; + len = (width+1)*(height+1); + RasMInterval domain = new RasMInterval("[0:"+width+",0:"+height+"]"); + RasMInterval domain2 = new RasMInterval("[1:3,1:3]"); + RasStorageLayout stl = new RasStorageLayout(); + stl.setTileSize(128); + + + /** + * test the GMArray + */ + System.out.println("\n\n### Testing GMArray with OID: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + try + { + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + } + catch(ODMGException e) + { + myTa.abort(); + System.err.println("Collection test does not exist: " + e.getMessage()); + } + + myQu.create("create collection test GreySet"); + RasGMArray mddConst = new RasGMArray(domain, 1, stl); + //RasGMArray mddConst = new RasGMArray(domain, 1); + byte[] data = new byte[len]; + mddConst.setObjectTypeName("GreyImage"); + + // test: get new OID from the server for GMArray and insert + System.out.println("new OID from server: " + myApp.getObjectId(mddConst)); + + for(int j = 0; j < data.length; j++) + data[j] = (byte)j; + + mddConst.setArray(data); + /* + System.out.println("\nbyte array: "); + for(int j=0; j<mddConst.getArray().length; j++) + { + System.out.print(" "+ mddConst.getArray()[j]); + } + */ + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddConst); + myQu.bind(mddConst); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + equal = true; + for(int j=0; j<mddConst.getArray().length; j++) + { + if(mddConst.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + if(!(myApp.getObjectId(mddConst).toString()).equals(myApp.getObjectId((RasGMArray)result).toString())) + equal = false; + System.out.println("result mdd: " + ((RasGMArray)mddConst).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + } + System.out.println("inserted and selected GMArray and OIDs are equal: " + equal); + //System.out.println("All results for test GMArray"); + } + + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasGMArray mddConst2 = new RasGMArray(mddConst); + mddConst2.setArray(data); + //System.out.println("\nbyte array2: "); + data = null; + equal = true; + for(int j=0; j<mddConst.getArray().length; j++) + { + //System.out.print(" "+ mddConst2.getArray()[j]); + if(mddConst.getArray()[j] != mddConst2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + + /** + * test the MArrayByte + */ + System.out.println("\n\n### Testing MArrayByte: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test GreySet"); + RasMArrayByte mddByte = new RasMArrayByte(domain, stl); + byte[] dataByte = new byte[len]; + mddByte.setObjectTypeName("GreyImage"); + + for(int j = 0; j < dataByte.length; j++) + dataByte[j] = (byte)j; + + mddByte.setArray(dataByte); + + //System.out.println("\nbyte array: "); + //for(int j=0; j<mddByte.getArray().length; j++) + //{ + //System.out.print(" "+ mddByte.getArray()[j]); + //} + + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddByte); + myQu.bind(mddByte); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + System.out.println("result mdd: " + ((RasGMArray)mddByte).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + equal = true; + for(int j=0; j<mddByte.getArray().length; j++) + { + if(mddByte.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + } + //System.out.println("All results for MArrayByte"); + System.out.println("inserted and selected MArrayByte are equal: " + equal); + } + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayByte mddByte2 = new RasMArrayByte(mddByte); + mddByte2.setArray(dataByte); + //System.out.println("\nbyte array2: "); + dataByte = null; + equal = true; + for(int j=0; j<mddByte.getArray().length; j++) + { + //System.out.print(" "+ mddByte2.getArray()[j]); + if(mddByte.getArray()[j] != mddByte2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + + /** + * test the MArrayInteger + */ + System.out.println("\n\n### Testing MArrayInteger: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test UShortSet"); + RasMArrayInteger mddInteger = new RasMArrayInteger(domain, stl); + int[] dataInteger = new int[len]; + //byte[] dataInteger = new byte[144]; + mddInteger.setObjectTypeName("UShortImage"); + + for(int j = 0; j < dataInteger.length; j++) + dataInteger[j] = j; + + mddInteger.setArray(dataInteger); + + //System.out.println("\nbyte array: "); + //for(int j=0; j<mddInteger.getArray().length; j++) + //{ + //System.out.print(" "+ mddInteger.getArray()[j]); + //} + + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddInteger); + myQu.bind(mddInteger); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + System.out.println("result mdd: " + ((RasGMArray)mddInteger).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + equal = true; + for(int j=0; j<mddInteger.getArray().length; j++) + { + if(mddInteger.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + } + //System.out.println("All results for MArrayInteger"); + System.out.println("inserted and selected MArrayInteger are equal: " + equal); + } + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayInteger mddInteger2 = new RasMArrayInteger(mddInteger); + mddInteger2.setArray(dataInteger); + dataInteger = null; + equal = true; + for(int j=0; j<mddInteger2.getArray().length; j++) + { + //System.out.print(" "+ mddInteger2.getArray()[j]); + if(mddInteger.getArray()[j] != mddInteger2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + + /* + System.out.println("\nspecial array2: "); + for(int j=0; j<mddInteger2.getIntArray().length; j++) + { + System.out.print(" "+ mddInteger2.getIntArray()[j]); + } + */ + + /** + * test the MArrayDouble + */ + System.out.println("\n\n### Testing MArrayDouble: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test DoubleSet"); + RasMArrayDouble mddDouble = new RasMArrayDouble(domain, stl); + double[] dataDouble = new double[len]; + //byte[] dataDouble = new byte[288]; + mddDouble.setObjectTypeName("DoubleImage"); + + for(double j = 0; j < dataDouble.length; j++) + dataDouble[(int)j] = j; + + mddDouble.setArray(dataDouble); + + //System.out.println("\nbyte array: "); + //for(int j=0; j<mddDouble.getArray().length; j++) + //{ + //System.out.print(" "+ mddDouble.getArray()[j]); + //} + + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddDouble); + myQu.bind(mddDouble); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + equal = true; + for(int j=0; j<mddDouble.getDoubleArray().length; j++) + { + if(mddDouble.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + System.out.println("result mdd: " + ((RasGMArray)mddDouble).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + } + //System.out.println("All results for MArrayDouble"); + System.out.println("inserted and selected MArrayDouble are equal: " + equal); + } + + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayDouble mddDouble2 = new RasMArrayDouble(mddDouble); + mddDouble2.setArray(dataDouble); + //System.out.println("byte array2: "); + dataDouble = null; + equal = true; + for(int j=0; j<mddDouble2.getArray().length; j++) + { + //System.out.print(" "+ mddDouble2.getArray()[j]); + if(mddDouble.getArray()[j] != mddDouble2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + + /* + System.out.println("\nspecial array2: "); + for(int j=0; j<mddDouble2.getDoubleArray().length; j++) + { + System.out.print(" "+ mddDouble2.getDoubleArray()[j]); + } + */ + + /** + * test the MArrayFloat + */ + System.out.println("\n\n### Testing MArrayFloat: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test FloatSet"); + RasMArrayFloat mddFloat = new RasMArrayFloat(domain, stl); + float[] dataFloat = new float[len]; + //byte[] dataFloat = new byte[144]; + mddFloat.setObjectTypeName("FloatImage"); + + for(float j = 0; j < dataFloat.length; j++) + dataFloat[(int)j] = j; + + mddFloat.setArray(dataFloat); + + //System.out.println("\nbyte array: "); + //for(int j=0; j<mddFloat.getArray().length; j++) + //{ + //System.out.print(" "+ mddFloat.getArray()[j]); + //} + + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddFloat); + myQu.bind(mddFloat); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + equal = true; + for(int j=0; j<mddFloat.getArray().length; j++) + { + if(mddFloat.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + System.out.println("result mdd: " + ((RasGMArray)mddFloat).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + } + //System.out.println("All results for MArrayFloat"); + System.out.println("inserted and selected MArrayFloat are equal: " + equal); + } + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayFloat mddFloat2 = new RasMArrayFloat(mddFloat); + mddFloat2.setArray(dataFloat); + //System.out.println("\nbyte array2: "); + dataFloat = null; + equal = true; + for(int j=0; j<mddFloat2.getArray().length; j++) + { + //System.out.print(" "+ mddFloat2.getArray()[j]); + if(mddFloat.getArray()[j] != mddFloat2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + /* + System.out.println("\nspecial array2: "); + for(int j=0; j<mddFloat2.getFloatArray().length; j++) + { + System.out.print(" "+ mddFloat2.getFloatArray()[j]); + } + */ + + /** + * test the MArrayShort + */ + System.out.println("\n\n### Testing MArrayShort: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test ShortSet"); + RasMArrayShort mddShort = new RasMArrayShort(domain, stl); + //RasMArrayShort mddShort4 = new RasMArrayShort(domain, stl); + //RasMArrayShort mddShort3 = new RasMArrayShort(domain, stl); + short[] dataShort = new short[len]; + //short[] dataShort4 = new short[len]; + //short[] dataShort3 = new short[len]; + //byte[] dataShort = new byte[72]; + mddShort.setObjectTypeName("ShortImage"); + //mddShort4.setObjectTypeName("ShortImage"); + //mddShort3.setObjectTypeName("ShortImage"); + + //System.out.println("new OID from server: " + myApp.getObjectId(mddShort)); + //System.out.println("new OID from server: " + myApp.getObjectId(mddShort4)); + for(int j = 0; j < dataShort.length; j++) + dataShort[j] = (short)j; + + //for(int j = 0; j < dataShort.length; j++) + //dataShort[j] = 1; + //for(int j = 0; j < dataShort4.length; j++) + //dataShort4[j] = 2; + //for(int j = 0; j < dataShort3.length; j++) + //dataShort3[j] = 3; + + + mddShort.setArray(dataShort); + //mddShort4.setArray(dataShort4); + //mddShort3.setArray(dataShort3); + /* + System.out.println("\nbyte array: "); + for(int j=0; j<mddShort.getArray().length; j++) + { + System.out.print(" "+ mddShort.getArray()[j]); + } + */ + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + myQu = myApp.newOQLQuery(); + //System.out.println("\ncollection created"); + //myQu.create("insert into test values $1"); + myQu.create("insert into test values $1"); + //System.out.println("mdd before sending: " + mddShort); + //myQu.bind("test"); + myQu.bind(mddShort); + //myQu.bind(mddShort4); + //myQu.bind(mddShort3); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + /* + myTa.begin(); + myQu = myApp.newOQLQuery(); + myQu.create("insert into test values $1"); + myQu.bind(mddShort4); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + myTa.begin(); + myQu = myApp.newOQLQuery(); + myQu.create("insert into test values $1"); + myQu.bind(mddShort3); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + */ + //System.out.println("collection inserted"); + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + equal = true; + for(int j=0; j<mddShort.getArray().length; j++) + { + if(mddShort.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + System.out.println("result mdd: " + ((RasGMArray)mddShort).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + } + //System.out.println("All results for MArrayShort"); + System.out.println("inserted and selected MArrayShort are equal: " + equal); + } + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayShort mddShort2 = new RasMArrayShort(mddShort); + mddShort2.setArray(dataShort); + //System.out.println("\nbyte array2: "); + dataShort = null; + equal = true; + for(int j=0; j<mddShort2.getArray().length; j++) + { + //System.out.print(" "+ mddShort2.getArray()[j]); + if(mddShort.getArray()[j] != mddShort2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + /* + System.out.println("\nspecial array2: "); + for(int j=0; j<mddShort2.getShortArray().length; j++) + { + System.out.print(" "+ mddShort2.getShortArray()[j]); + } + */ + + /** + * test the MArrayLong + */ + System.out.println("\n\n### Testing MArrayLong: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test ULongSet"); + RasMArrayLong mddLong = new RasMArrayLong(domain, stl); + long[] dataLong = new long[len]; + //byte[] dataLong = new byte[288]; + mddLong.setObjectTypeName("ULongImage"); + + for(long j = 0; j < dataLong.length; j++) + dataLong[(int)j] = j; + mddLong.setArray(dataLong); + + /* + System.out.println("\nbyte array: "); + for(int j=0; j<mddLong.getArray().length; j++) + { + System.out.print(" "+ mddLong.getArray()[j]); + } + */ + + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddLong); + myQu.bind(mddLong); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + equal = true; + for(int j=0; j<((RasGMArray)result).getArray().length; j++) + { + if(mddLong.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + System.out.println("result mdd: " + ((RasGMArray)mddLong).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + } + //System.out.println("All results for MArrayLong"); + System.out.println("inserted MArrayInteger and selected MArrayLong are equal: " + equal); + } + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayLong mddLong2 = new RasMArrayLong(mddLong); + mddLong2.setArray(dataLong); + //System.out.println("\nbyte array2: "); + dataLong = null; + equal = true; + for(int j=0; j<mddLong2.getArray().length; j++) + { + //System.out.print(" "+ mddLong2.getArray()[j]); + if(mddLong.getArray()[j] != mddLong2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + + System.out.println("\nspecial array: "); + for(int j=0; j<((RasMArrayLong)result).getLongArray().length; j++) + { + System.out.print(" "+ ((RasMArrayLong)result).getLongArray()[j]); + } + + + /** + * testing intersection + */ + System.out.println("\n\n### Testing intersection:"); + mddConst2.intersectionWith(domain2); + mddByte2.intersectionWith(domain2); + mddDouble2.intersectionWith(domain2); + mddFloat2.intersectionWith(domain2); + mddInteger2.intersectionWith(domain2); + mddLong2.intersectionWith(domain2); + mddShort2.intersectionWith(domain2); + System.out.println("OK\n"); + + /** + * testing OIDs + */ + myQu = myApp.newOQLQuery(); + myQu.create("SELECT oid(img) FROM test AS img"); + //myQu.create("SELECT img FROM test AS img where (oid(img)=231425)"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + //System.out.println("OID: " + result); + } + //System.out.println("All results"); + + } + + /** + * get new OID + */ + System.out.println("### Testing OIDs:"); + myTa.begin(); + myApp.getObjectId(new RasGMArray()); + myTa.commit(); + + System.out.println( "Closing database ..." ); + myDb.close(); + + // get new OID without open TA + RasGMArray gmar = new RasGMArray(); + equal = true; + if(!myApp.getObjectId(gmar).equals(gmar.getOID().toString())) + equal = false; + System.out.println("same OID on client and server side: " + equal); + + } + catch (RasException e) + { + System.out.println("!!!!!!!!!!!!!!!!!!!!While testing!!!!!!!!!!!!!!!!!!"); + System.out.println("An RasException has occurred: " + e.getMessage()); + System.out.println("Try to abort the transaction ..."); + if(myTa != null) myTa.abort(); + + try + { + System.out.println("Try to close the database ..."); + if(myDb != null) myDb.close(); + } + catch ( org.odmg.ODMGException exp ) + { + System.err.println("Could not close the database: " + exp.getMessage()); + } + } + catch (RasRuntimeException e) + { + System.out.println("!!!!!!!!!!!!!!!!!!!!While testing!!!!!!!!!!!!!!!!!!"); + System.out.println("An RasRuntimeException has occurred: " + e.getMessage()); + System.out.println("Try to abort the transaction ..."); + if(myTa != null) myTa.abort(); + + try + { + System.out.println("Try to close the database ..."); + if(myDb != null) myDb.close(); + } + catch ( org.odmg.ODMGException exp ) + { + System.err.println("Could not close the database: " + exp.getMessage()); + } + } + catch (org.odmg.ODMGException e) + { + System.out.println("!!!!!!!!!!!!!!!!!!!!While testing!!!!!!!!!!!!!!!!!!"); + System.out.println("An ODMGException has occurred: " + e.getMessage()); + System.out.println("Try to abort the transaction ..."); + if(myTa != null) myTa.abort(); + + try + { + System.out.println("Try to close the database ..."); + if(myDb != null) myDb.close(); + } + catch ( org.odmg.ODMGException exp ) + { + System.err.println("Could not close the database: " + exp.getMessage()); + } + } + System.out.println( "Done." ); + + } +} + diff --git a/java/rasj/test/TestOdmg.java b/java/rasj/test/TestOdmg.java new file mode 100644 index 0000000..da10505 --- /dev/null +++ b/java/rasj/test/TestOdmg.java @@ -0,0 +1,430 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/************************************************************* + * + * + * PURPOSE: + * test rasj with some queries + * @param --server s - use server s (default: localhost) + * @param --port p - use server port p (default: 7001) + * @param --database d - use database d (default: RASBASE) + * @param --user u - log in as user u (default: rasguest) + * @param --passwd p - log in with password p (default: rasguest) + * + * PREREQUISITES: + * - needs an HTTP server + * - needs write access to database + * - database must know type GreySet + * + * + * COMMENTS: + * - no parameter line error handling + * was formerly in rasj/odmg/test, this has been merged + ************************************************************/ + +import rasj.*; +import rasj.global.*; +import org.odmg.*; +import rasj.odmg.*; + +import java.util.*; +import java.io.*; + +public class TestOdmg implements RasGlobalDefs + { + + /** + * prefixes for test output + **/ + static final String PREFIX_PROGRAM = "+++ +++ +++ "; + static final String PREFIX_TESTSET = "+++ +++ "; + static final String PREFIX_TESTCASE = "+++ "; + + /** + * std error tag printed if a test fails + **/ + static final String ERROR_TAG = "ERROR: "; + + /** + * default values (override with cmd line option) + **/ + static final String DEFAULT_HOST = "localhost"; + static final int DEFAULT_PORT = 7001; + static final String DEFAULT_BASE = "RASBASE"; + static final String DEFAULT_USER = "rasguest"; + static final String DEFAULT_PASSWD = "rasguest"; + + public static void main(String[] args) throws Exception + { + + String serv = DEFAULT_HOST; + int port = DEFAULT_PORT; + String base = DEFAULT_BASE; + String user = DEFAULT_USER; + String passwd = DEFAULT_PASSWD; + boolean wrongUsage = false; // error in cmd line params? + RasImplementation myImp = null; + + for (int i=args.length-1; i>=0; i--) + { + if (args[i].equals("--server")) + serv = args[i+1]; + else if (args[i].equals("--port")) + { + try + { + port = Integer.parseInt(args[i+1]); + } + catch(Exception e) + { + wrongUsage = true; + } + } + else if (args[i].equals("--database")) + base = args[i+1]; + else if (args[i].equals("--user")) + user = args[i+1]; + else if (args[i].equals("--passwd")) + passwd = args[i+1]; + } + + if (wrongUsage) + { + System.out.println( "Usage: ODMGtest [--server s] [--port p] [--database d] [--user u] [--passwd p]" ); + System.out.println( "defaults: server=" + DEFAULT_HOST + ", port=" + DEFAULT_PORT + ", database=" + DEFAULT_BASE ++ ", user=" + DEFAULT_USER + ", passwd=" + DEFAULT_PASSWD ); + System.exit(-1); + } + + System.out.println( "rasdaman system test v5.1revC: testing ODMG queries." ); + System.out.println( PREFIX_PROGRAM + "system test started, using server " + serv + ", port " + port + ", database " + base + ", user=" + user + ", passwd=" + passwd ); + + myImp = new RasImplementation("http://" + serv + ":" + port); + + // START tests ---------------------------------------------- + testQueries( myImp, base ); + // END tests ------------------------------------------------ + + System.out.println( PREFIX_PROGRAM + "system test done." ); + return; + } // main() + + /** + * test database queries + * any eventual exception that is not caught here is an error, and will cause an abort + **/ + static void testQueries( RasImplementation imp, String database ) throws Exception + { + System.out.println( PREFIX_TESTSET + "testing queries started." ); + + // objectTest(); // - just to test setObjectName() which now verifies that the name is a valid identifier + + Database mydb = null; + Transaction myta = null; + RasGMArray myMDD = null; + OQLQuery myQuery = null; + + + /********************* + * test update query * + *********************/ + // create some test data + try + { + System.out.println("Start creating test arrays ..."); + myMDD = new RasGMArray(new RasMInterval("[1:400,1:400]"),1); + byte[] mydata = new byte[160000]; + for(int y=0; y<400; y++) + { + for(int x=0; x<400; x++) + { + if((x>99 && x<151) || (x>299 && x<351)) + mydata[y*399+x]=100; + else + mydata[y*399+x]=0; + } + } + myMDD.setArray(mydata); + myMDD.setObjectTypeName("GreyImage"); + + RasStorageLayout myLayout = new RasStorageLayout(); + //myLayout.setTileSize(640000); + myLayout.setTileDomain("[1:100,1:70]"); + myMDD.setStorageLayout(myLayout); + + System.out.println("Created Test Data:"); + System.out.println(myMDD); + } + + catch ( Exception e ) + { + System.out.println("ERROR: "); + System.out.println(e.getMessage()); + System.exit(-1); + } + + // now access the database and start a transaction + try { + mydb = imp.newDatabase(); + System.out.println("Open Database ..."); + mydb.open( database, Database.OPEN_READ_WRITE ); + System.out.println(" ok."); + myta = imp.newTransaction(); + System.out.println("Begin transaction ..."); + myta.begin(); + System.out.println(" ok."); + } + + catch ( Exception e ) { + System.out.println("ERROR: "); + System.out.println(e.getMessage()); + + if(myta.isOpen()) + { + System.out.println("Abort transaction ..."); + myta.abort(); + } + System.out.println("Close database ..."); + try { + mydb.close(); + System.out.println(" ok."); + } + catch ( Exception e2 ) { + } + System.out.println("Exiting..."); + System.exit(-1); + } + + // create the test collection + try { + System.out.println("Create a new test collection ..."); + myQuery = imp.newOQLQuery(); + myQuery.create("create collection testCollection GreySet"); + //myQuery.create("create collection $1 GreySet"); + //myQuery.bind("testCollection"); + myQuery.execute(); + myta.commit(); + myta.begin(); + System.out.println(" ok."); + } + + catch ( Exception e) { + System.out.println("ERROR: "); + System.out.println(e.getMessage()); + System.out.println("Try to remove the test collection ..."); + try { + myQuery.create("drop collection testCollection"); + myQuery.execute(); + myta.commit(); + } + catch ( Exception e2 ) { + } + + if(myta.isOpen()) + { + System.out.println("Abort transaction ..."); + myta.abort(); + } + System.out.println("Close database ..."); + try { + mydb.close(); + System.out.println(" ok."); + } + catch ( Exception e3 ) { + } + + System.out.println("Exiting..."); + System.exit(-1); + } + + // testquery with empty result + /* + try { + System.out.println("Define a testquery with an empty result... "); + myQuery.create("select a from ImgRGBA as a where oid(a) <= 0"); + System.out.println("Send the query ..."); + DSet myResult = (DSet) myQuery.execute(); + + Iterator iter = myResult.iterator(); + System.out.println("Number of results: " + myResult.size()); + + + while(iter.hasNext()) + { + System.out.println("Ergebnis:"); + System.out.println(iter.next()); + } + + System.out.println(" ok."); + System.out.println("Commit transaction ..."); + System.out.println(" ok."); + } + + catch ( Exception e ) { + System.out.println("ERROR: "); + System.out.println(e.getMessage()); + + if(myta.isOpen()) + { + System.out.println("Abort transaction ..."); + myta.abort(); + } + System.out.println("Close database ..."); + try { + mydb.close(); + System.out.println(" ok."); + } + catch ( Exception e2 ) { + } + System.out.println("Exiting..."); + System.exit(-1); + } + */ + + // now insert MDDS and commit + try { + System.out.println("Define the update query and bind the parameters ..."); + myQuery.create("insert into testCollection VALUES $1"); + //myQuery.create("insert into testCollection VALUES $1"); + myQuery.bind(myMDD); + System.out.println(" ok."); + System.out.println("Send the query ..."); + myQuery.execute(); + System.out.println(" ok."); + System.out.println("Commit transaction ..."); + myta.commit(); + System.out.println(" ok."); + } + + catch ( Exception e ) { + System.out.println("ERROR: "); + System.out.println(e.getMessage()); + + if(myta.isOpen()) + { + System.out.println("Abort transaction ..."); + myta.abort(); + } + System.out.println("Close database ..."); + try { + mydb.close(); + System.out.println(" ok."); + } + catch ( Exception e2 ) { + } + System.out.println("Exiting..."); + System.exit(-1); + } + + // start new transaction and todo: read back the testimage + try { + System.out.println("Start new transaction ..."); + myta.begin(); + myQuery = imp.newOQLQuery(); + myQuery.create("select testCollection from testCollection"); + //myQuery.create("create collection $1 GreySet"); + //myQuery.bind("testCollection"); + myQuery.execute(); + myta.commit(); + System.out.println(" ok."); + myta.begin(); + + } + + catch ( Exception e ) { + System.out.println("ERROR: "); + System.out.println(e.getMessage()); + + if(myta.isOpen()) + { + System.out.println("Abort transaction ..."); + myta.abort(); + } + System.out.println("Close database ..."); + try { + mydb.close(); + System.out.println(" ok."); + } + catch ( Exception e2 ) { + } + System.out.println("Exiting..."); + System.exit(-1); + } + + // todo: compare to the original image + + // drop test collection + try { + System.out.println("Drop test collection ..."); + myQuery = imp.newOQLQuery(); + myQuery.create("drop collection testCollection"); + myQuery.execute(); + myta.commit(); + mydb.close(); + System.out.println(" ok."); + } + + catch ( Exception e) { + System.out.println("ERROR: "); + System.out.println(e.getMessage()); + + if(myta.isOpen()) + { + System.out.println("Abort transaction ..."); + myta.abort(); + } + System.out.println("Close database ..."); + try { + mydb.close(); + System.out.println(" ok."); + } + catch ( Exception e2 ) { + } + System.out.println("Exiting..."); + System.exit(-1); + } + + System.out.println( PREFIX_TESTSET + "testing queries done.\n" ); + return; + } // testQueries() + + public static void objectTest() + { + System.out.println("Set object name test - in"); + + RasObject dummy = new RasObject(); + + dummy.setObjectName("goodName"); + + System.out.println("Set name=" + dummy.getObjectName()); + + dummy.setObjectName("bad-Name"); + + System.out.println("Set name=" + dummy.getObjectName()); + + System.out.println("Set object name test - out"); + + } + +} // TestOdmg + diff --git a/java/rasj/test/TestQuery.java b/java/rasj/test/TestQuery.java new file mode 100644 index 0000000..362b99f --- /dev/null +++ b/java/rasj/test/TestQuery.java @@ -0,0 +1,143 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/************************************************************* + * + * + * PURPOSE: + * test rasj: simple open/read query/close cycle. + * rasj test program for executing a query against some rasdaman database. + * Note: database is opened readonly, so send only SELECT queries. + * + * @param --server s - use server s (default: localhost) + * @param --port p - use server port p (default: 7001) + * @param --database d - use database d (default: RASBASE) + * @param --user u - log in as user u (default: rasguest) + * @param --passwd p - log in with password p (default: rasguest) + * @param --query q - send SELECT query string q to server (default: "select r from RAS_COLLECTIONNAMES as r"") + * @param --count c - execute query c times (default: 1) + * + * + * COMMENTS: + * - no parameter line error handling + ************************************************************/ + +import rasj.*; +import rasj.odmg.*; +import org.odmg.*; +import java.util.*; +import java.io.*; + +public class TestQuery + { + + public static void main( String[] args ) + { + String server = "localhost"; + String port = "7001"; + String base = "RASBASE"; + String user = "rasguest"; + String passwd = "rasguest"; + String query = "select r from RAS_COLLECTIONNAMES as r"; + int count = 1; + + if (args.length == 0) + { + System.out.println( "usage: TestQuery [options]" ); + System.out.println( "options:" ); + System.out.println( " --server s - use server s (default: localhost)" ); + System.out.println( " --port p - use server port p (default: 7001)" ); + System.out.println( " --database d - use database d (default: RASBASE)" ); + System.out.println( " --user u - log in as user u (default: rasguest)" ); + System.out.println( " --passwd p - log in with password p (default: rasguest)" ); + System.out.println( " --query q - send SELECT query string q to server (default: select r from RAS_COLLECTIONNAMES as r)" ); + System.out.println( " --count c - execute query c times (default: 1)" ); + return; + } + + for (int i=args.length-1; i>=0; i--) + { + if (args[i].equals("--server")) + server = args[i+1]; + if (args[i].equals("--port")) + port = args[i+1]; + if (args[i].equals("--database")) + base = args[i+1]; + if (args[i].equals("--user")) + user = args[i+1]; + if (args[i].equals("--passwd")) + passwd = args[i+1]; + if (args[i].equals("--query")) + query = args[i+1]; + if (args[i].equals("--count")) + count = Integer.parseInt(args[i+1]); + } + + System.out.println( "Query test started with server=" + server + ", port=" + port + ", database=" + base + ", user=" + user + ", count=" + count + ", query=" + query ); + + try + { + RasImplementation myApp = new RasImplementation("http://"+server+":"+port); + myApp.setUserIdentification(user, passwd); + + System.out.println( "opening database..." ); + Database myDb = myApp.newDatabase(); + myDb.open( base, Database.OPEN_READ_WRITE ); + + System.out.println( "starting transaction..." ); + Transaction myTa = myApp.newTransaction(); + myTa.begin(); + + for (int i = 1; i <= count; i++) + { + + System.out.print( "sending query #" + i + "..." ); + OQLQuery myQu = myApp.newOQLQuery(); + myQu.create(query); + DBag result = (DBag) myQu.execute(); + + System.out.println( "result is: " + result ); + + } + + System.out.println( "closing transaction..." ); + myTa.commit(); + + // System.out.println( "sending query out of TA, must produce an error..." ); + // OQLQuery myQu2 = myApp.newOQLQuery(); + // myQu2.create(query); + // DBag result2 = (DBag) myQu2.execute(); + + System.out.println( "closing database..." ); + myDb.close(); + + } + catch(Exception e) + { + System.err.println( e.getMessage() ); + } + + System.out.println( "Query test done." ); + + } // main() + +} // TestQuery diff --git a/java/rasj/test/TestQuery.sh b/java/rasj/test/TestQuery.sh new file mode 100644 index 0000000..ca3b2fe --- /dev/null +++ b/java/rasj/test/TestQuery.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# TestQuery.sh: test rasj query interface +# where rasj.jar is expected: +export RASJ=$RMANBASE/java/rasj.jar +#export RASJ=~rasdaman/jlib/rasj.jar + +java -DRMANPROTOCOL=RNP -cp .:$RASJ:$CLASSPATH TestQuery --query "SELECT jpeg(( marray x in [0:599,0:599] values {255c,255c,0c} ) overlay scale(img0[2011:2315,2543:2847],[1:600,1:600]) * { 1c, 1c, 1c}) FROM vat_rgbdop2_8 AS img0" $* 2>&1 + diff --git a/java/rasj/test/TestRasInterval.java b/java/rasj/test/TestRasInterval.java new file mode 100644 index 0000000..27450fd --- /dev/null +++ b/java/rasj/test/TestRasInterval.java @@ -0,0 +1,314 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/** *********************************************************** + * <pre> + * + * PURPOSE: + * + * + * COMMENTS: + * - on error, an exception is thrown (java main() knows no exit status) + * + * </pre> + *********************************************************** */ + +import java.util.StringTokenizer; +import java.lang.Integer; +import java.lang.Long; +import rasj.*; +import rasj.odmg.*; + +public class TestRasInterval + { + /** + * constants used in this test + **/ + // prefixes for test output + static final String PREFIX_PROGRAM = "+++ +++ +++ "; + static final String PREFIX_TESTSET = "+++ +++ "; + static final String PREFIX_TESTCASE = "+++ "; + + /** + * std error tag printed upon failure + **/ + static final String ERROR_TAG = "ERROR: "; + + /** + * main program for testing + * on error, an exception is thrown (java main() knows no exit status) + **/ + public static void main(String argv[]) throws Exception + { + System.out.println( "rasdaman system test v5.1revC: TestRasInterval." ); + System.out.println( PREFIX_PROGRAM + "system test started." ); + + // -- START test cases ------------------------------------------------- + testInterval(); + // -- END test cases --------------------------------------------------- + + System.out.println( PREFIX_PROGRAM + "system test done." ); + return; + } + + /** + * test the RasInterval class (no db access) + * any eventual exception that is not caught here is an error, and will cause an abort + **/ + static void testInterval() throws RasResultIsNoIntervalException, RasDimensionMismatchException, RasIndexOutOfBoundsException, RasStreamInputOverflowException + { + // create a new RasSInterval + System.out.println("\n############################ test sintervals: "); + RasSInterval s1 = new RasSInterval(100,200); + RasSInterval s2 = new RasSInterval("150:400"); + + // get upper bound + boolean b1 = false; + if(s2.high() == 400) + b1 = true; + System.out.println("upper bound is correct: " + b1); + + // test if lower bound is fixed + boolean b2; + b1 = false; + b1 = s2.isLowFixed(); + System.out.println("lower bound is fix: " + b1); + + // test if interval intersects with another interval + // (the return value shows the kind of intersection) + int j; + j = s1.intersectsWith(s2); + b1 = false; + if(j != -1) + b1 = true; + System.out.println("s1 intersects with s2: " + b1); + + RasSInterval sint1 = new RasSInterval(100,200); + RasSInterval sint2 = new RasSInterval("150 :400 "); + RasSInterval sint3 = new RasSInterval("50:180"); + + b1 = false; + sint1.setHigh('*'); + sint1.setLow(400); + if(sint1.low() == 400) + b1 = true; + sint1.setLow('*'); + sint1.setHigh(500); + if((sint1.high() == 500) && b1) + b1 = true; + else + b1 = false; + System.out.println("setLow and setHigh are OK: " + b1); + + sint1.setInterval('*',500); + b1 = !sint1.isLowFixed(); + b1 = sint1.isHighFixed() && b1; + System.out.println("low is open high is fixed: " + b1); + + b1 = false; + if(sint1.intersectsWith(sint1) != -1) + b1 = true; + + if(sint3.closureOf(sint2, sint1).equals(sint1) && + sint3.closureWith(sint2).equals(sint1) && + sint3.createClosure(sint2).equals(sint1)) + b1 = b1 && true; + + sint1.setInterval(90, 105); + sint2.setInterval(100, 110); + if(sint2.createDifference(sint1).equals(new RasSInterval(90, 100)) && + sint3.createIntersection(sint2).equals(new RasSInterval(100, 110))) + b1 = b1 && true; + + if(sint3.createUnion(sint2).equals(sint1) && + sint1.differenceOf(sint1, sint2).equals(new RasSInterval(90, 100)) && + sint1.differenceWith(sint2).equals(new RasSInterval(100, 110))) + b1 = b1 && true; + + if(sint3.intersectionOf(sint2, sint1).equals(new RasSInterval(100, 100)) && + sint3.intersectionWith(sint2).equals(new RasSInterval(100, 100))) + b1 = b1 && true; + + b1 = b1 && !sint3.equals(sint2); + if(sint3.unionOf(sint1, sint2).equals(new RasSInterval(90, 110)) && + sint3.unionWith(sint2).equals(new RasSInterval(90, 110))) + b1 = b1 && true; + System.out.println("operations of sintervals are correct: " + b1); + + + + // create new RasMInterval + System.out.println("\n############################ test mintervals: "); + RasMInterval mint1 = new RasMInterval("[567:3253,666:888]"); + RasMInterval mint2 = new RasMInterval("[678:4000,777:999]"); + RasMInterval mint3 = new RasMInterval("[777:900,888:1000]"); + RasMInterval mint4 = new RasMInterval(2); + b1 = false; + if((mint2.dimension() == 2) && (mint1.dimension() == 2)) + b1 = true; + System.out.println("dimensions of mintervals are correct: " + b1); + + b1 = false; + mint1 = new RasMInterval("[500:3000,600:800]"); + mint2 = new RasMInterval("[600:1000,700:750]"); + b1 = mint1.intersectsWith(mint2); + mint1 = new RasMInterval("[567:3253,666:888]"); + mint2 = new RasMInterval("[678:4000,777:999]"); + if(mint3.closureOf(mint2, mint1).toString().equals(new RasMInterval("[567:4000,666:999]").toString())) + b1 = b1 && true; + else b1 = false; + if(mint3.closureWith(mint2).toString().equals(new RasMInterval("[567:4000,666:999]").toString())) + b1 = b1 && true; + else b1 = false; + if(mint3.createClosure(mint2).toString().equals(new RasMInterval("[567:4000,666:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = new RasMInterval("[678:2000,777:888]"); + mint3 = mint3.createDifference(mint2); + if(mint3.toString().equals(new RasMInterval("[2000:4000,888:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = new RasMInterval("[678:2000,777:888]"); + mint3 = mint3.createDifference(mint2); + if(mint3.toString().equals(new RasMInterval("[2000:4000,888:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = new RasMInterval("[678:2000,777:888]"); + mint3 = mint3.createIntersection(mint2); + if(mint3.toString().equals(new RasMInterval("[678:2000,777:888]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = new RasMInterval("[678:2000,777:888]"); + mint2 = new RasMInterval("[1000:4000,750:999]"); + mint3 = mint3.createUnion(mint2); + if(mint3.toString().equals(new RasMInterval("[678:4000, 750:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint2 = new RasMInterval("[1000:4000,800:999]"); + mint1 = mint1.differenceOf(mint3, mint2); + if(mint1.toString().equals(new RasMInterval("[678:1000,750:800]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = mint3.intersectionOf(mint2, mint1); + if(mint3.toString().equals(new RasMInterval("[1000:1000,800:800]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = mint3.intersectionWith(mint2); + if(mint3.toString().equals(new RasMInterval("[1000:1000,800:800]").toString())) + b1 = b1 && true; + else b1 = false; + b1 = b1 && !mint3.equals(mint2); + mint3 = mint3.unionOf(mint1, mint2); + if(mint3.toString().equals(new RasMInterval("[678:4000,750:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = mint3.unionWith(mint2); + if(mint3.toString().equals(new RasMInterval("[678:4000,750:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint2 = mint2.differenceWith(mint3); + if(mint2.toString().equals(new RasMInterval("[678:1000,750:800]").toString())) + b1 = b1 && true; + else b1 = false; + System.out.println("operations of mintervals are correct: " + b1); + + // Types + /////////////////////////////////////////// + System.out.println("\n############################ test types: "); + String s = "marray <char, 1>"; + RasType rType = RasType.getAnyType(s); + RasBaseType rb; + + if(rType.getClass().getName().equals("rasj.RasMArrayType")) + { + RasMArrayType tmp = (RasMArrayType)rType; + rb = tmp.getBaseType(); + + System.out.println("OK"); + } + else + System.out.println("element of MDD Collection is no MArray."); + + boolean b3; + b3 = !rType.isStructType(); + System.out.println(b3); + + + // StorageLayout + /////////////////////////////////////////// + System.out.println("\n############################ test storage layout: "); + RasGMArray myMDD = new RasGMArray(new RasMInterval("[1:400,1:400]"),1); + byte[] mydata = new byte[160000]; + for(int y=0; y<400; y++) + { + for(int x=0; x<400; x++) + { + if((x>99 && x<151) || (x>299 && x<351)) + mydata[y*399+x]=100; + else + mydata[y*399+x]=0; + } + } + + myMDD.setArray(mydata); + myMDD.setObjectTypeName("GreyImage"); + + RasStorageLayout myLayout = new RasStorageLayout(); + + myLayout.setTileDomain("[1:100,1:70]"); + // you can either set the TileSize or the TileDomain + myLayout.setTileSize(32); + myMDD.setStorageLayout(myLayout); + if(myMDD.getStorageLayout().getTileSize() == 32) + System.out.println("OK"); + + + //GMarray//////////////////////////////////////////////////////////////////////////////////////////////////////////////// + RasGMArray array1 = new RasGMArray(); + RasGMArray array2 = new RasGMArray(mint1, 8); + + myMDD.getCell(new RasPoint(1,1)); + + System.out.println("OK"); + + + //Ausgabe//////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /* + System.out.println("Array1 " + array1); + System.out.println("Array2 " + array2); + + System.out.println("Punkt1 " + p1); + System.out.println("Punkt2 " + p2); + + System.out.println("Sinterval1 " + s1); + System.out.println("Sinterval2 " + s2); + System.out.println("Sinterval3 " + sint3); + + System.out.println("j = " + j); + //System.out.println("b1 = " + b1); + //System.out.println("b2 = " + b2); + System.out.println("b3 = " + b3); + */ + + } + + } // TestRasInterval diff --git a/java/rasj/test/TestRasPoint.java b/java/rasj/test/TestRasPoint.java new file mode 100644 index 0000000..6402bf0 --- /dev/null +++ b/java/rasj/test/TestRasPoint.java @@ -0,0 +1,373 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/** *********************************************************** + * <pre> + * + * PURPOSE: + * test rasj class RasPoint. + * + * + * COMMENTS: + * - testing philosophy is to run all tests and report. no exit code / exception + * is used for error indication; look into the output for ERROR_TAG instead. + * - unexpected exceptions are not caught, hence will make gmake fail and show the error + * - every test that fails must print a line containing ERROR_TAG + * </pre> + *********************************************************** */ + +import java.util.StringTokenizer; +import java.lang.Integer; +import java.lang.Long; +import rasj.*; +import rasj.odmg.*; + +public class TestRasPoint + { + /** + * constants used in this test + **/ + // prefixes for test output + static final String PREFIX_PROGRAM = "+++ +++ +++ "; + static final String PREFIX_TESTSET = "+++ +++ "; + static final String PREFIX_TESTCASE = "+++ "; + + static final int COORD_1 = 11; + static final int COORD_2 = 22; + static final int COORD_3 = 33; + static final int COORD_4 = 44; + static final int COORD_5 = 55; + + /** + * std error tag printed if a test fails + **/ + static final String ERROR_TAG = "ERROR: "; + + /** + * main program for testing + * on error, an exception is thrown (java main() knows no exit status) + **/ + public static void main(String argv[]) throws Exception + { + System.out.println( "rasdaman system test v5.1revC: testing class RasPoint." ); + System.out.println( PREFIX_PROGRAM + "system test started." ); + + // -- START test cases ------------------------------------------------- + testConstructor(); + // testcomparedWith(); + // testEquals(); + // testStream(); + // testSetItem(); + // testSetTo(); + testAdd(); + // testmult(); + // -- END test cases --------------------------------------------------- + + System.out.println( PREFIX_PROGRAM + "system test done." ); + return; + } + + /** + * test the RasPoint class constructor + * any eventual exception that is not caught here is an error, and will cause an abort + **/ + static void testConstructor() throws RasDimensionMismatchException, RasIndexOutOfBoundsException + { + System.out.println( PREFIX_TESTSET + "testing constructor started." ); + + // default constructor + System.out.print( PREFIX_TESTCASE + "default constructor..." ); + RasPoint p_default = new RasPoint(); + if (p_default == null) + System.out.println( ERROR_TAG + "result is null." ); + else if (! p_default.equals( p_default ) ) + System.out.println( ERROR_TAG + "point notEqual to itself." ); + else + System.out.println( "OK, result=" + p_default + ", dimension is " + p_default.dimension() ); + + // stream constructor + // ------------------ + + System.out.print( PREFIX_TESTCASE + "stream constructor, illegal dimension -1..." ); + try + { + RasPoint p_stream_m1 = new RasPoint( -1 ); + if (p_stream_m1 != null) + System.out.println( ERROR_TAG + "result is not null." ); + else + System.out.println( "OK." ); + } + catch(NegativeArraySizeException e) + { + System.out.println( "OK: " + e.getMessage() ); + } + + System.out.print( PREFIX_TESTCASE + "stream constructor, dimension 0..." ); + RasPoint p_stream_0 = new RasPoint( 0 ); + if (p_stream_0.dimension() != 0) + System.out.println( ERROR_TAG + "wrong dimension." ); + else + System.out.println( "OK." ); + + // --- easy-to-use constructor ------------------------------------------------------- + + // 2-D constructor + System.out.print( PREFIX_TESTCASE + "2D easy to use constructor..." ); + RasPoint p_2d_easy = new RasPoint( COORD_1, COORD_2 ); + if (p_2d_easy == null) + System.out.println( ERROR_TAG + "result is null." ); + else if (p_2d_easy.dimension() != 2) + System.out.println( ERROR_TAG + "dimension is not 2 but " + p_2d_easy.dimension() ); + else if (p_2d_easy.item(0) != COORD_1) + System.out.println( ERROR_TAG + "item(0) returns wrong component " + p_2d_easy.item(0) ); + else if (p_2d_easy.item(1) != COORD_2) + System.out.println( ERROR_TAG + "item(1) returns wrong component " + p_2d_easy.item(0) ); + else if (! p_2d_easy.equals( p_2d_easy ) ) + System.out.println( ERROR_TAG + "point not equal to itself." ); + else if ( p_2d_easy.notEquals( p_2d_easy ) ) + System.out.println( ERROR_TAG + "point notEqual to itself." ); + else + System.out.println( "OK, result=" + p_2d_easy ); + + // 3-D constructor + System.out.print( PREFIX_TESTCASE + "3D easy to use constructor..." ); + RasPoint p_3d_easy= new RasPoint( COORD_1, COORD_2, COORD_3 ); + if (p_3d_easy== null) + System.out.println( ERROR_TAG + "result is null." ); + else if (p_3d_easy.dimension() != 3) + System.out.println( ERROR_TAG + "dimension is not 3 but " + p_3d_easy.dimension() ); + else if (p_3d_easy.item(2) != COORD_3) + System.out.println( ERROR_TAG + "item(2) returns wrong component " + p_3d_easy.item(0) ); + else if (! p_3d_easy.equals( p_3d_easy) ) + System.out.println( ERROR_TAG + "point not equal to itself." ); + else if ( p_3d_easy.notEquals( p_3d_easy) ) + System.out.println( ERROR_TAG + "point notEqual to itself." ); + else + System.out.println( "OK, result=" + p_3d_easy); + + // 4-D constructor + System.out.print( PREFIX_TESTCASE + "4D easy to use constructor..." ); + RasPoint p_4d_easy = new RasPoint( COORD_1, COORD_2, COORD_3, COORD_4 ); + if (p_4d_easy == null) + System.out.println( ERROR_TAG + "result is null." ); + else if (p_4d_easy.dimension() != 4) + System.out.println( ERROR_TAG + "dimension is not 4 but " + p_4d_easy.dimension() ); + else if (p_4d_easy.item(3) != COORD_4) + System.out.println( ERROR_TAG + "item(3) returns wrong component " + p_4d_easy.item(0) ); + else if (! p_4d_easy.equals( p_4d_easy ) ) + System.out.println( ERROR_TAG + "point not equal to itself." ); + else if ( p_4d_easy.notEquals( p_4d_easy ) ) + System.out.println( ERROR_TAG + "point notEqual to itself." ); + else + System.out.println( "OK, result=" + p_4d_easy ); + + // 5-D constructor + System.out.print( PREFIX_TESTCASE + "5D easy to use constructor..." ); + RasPoint p_5d_easy = new RasPoint( COORD_1, COORD_2, COORD_3, COORD_4, COORD_5 ); + if (p_5d_easy == null) + System.out.println( ERROR_TAG + "result is null." ); + else if (p_5d_easy.dimension() != 5) + System.out.println( ERROR_TAG + "dimension is not 5 but " + p_5d_easy.dimension() ); + else if (p_5d_easy.item(4) != COORD_5) + System.out.println( ERROR_TAG + "item(4) returns wrong component " + p_5d_easy.item(0) ); + else if (! p_5d_easy.equals( p_5d_easy ) ) + System.out.println( ERROR_TAG + "point not equal to itself." ); + else if ( p_5d_easy.notEquals( p_5d_easy ) ) + System.out.println( ERROR_TAG + "point notEqual to itself." ); + else + System.out.println( "OK, result=" + p_5d_easy ); + + // --- string constructor ------------------------------------------------------- + + // illegal string format + // FIXME: bug PB4 + System.out.println( ERROR_TAG + "PB4: string constructor, illegal string formats." ); + + // System.out.print( PREFIX_TESTCASE + "string constructor, illegal string format (no [)..." ); + // RasPoint p_si = new RasPoint( COORD_1 + "," + COORD_2 + "]" ); + // System.out.println( "point is: " + p_si ); + // if (! p_si.equals( new RasPoint( "[" + COORD_1 + "," + COORD_2 + "]" ) ) ) + // System.out.println( ERROR_TAG + "wrong point value." ); + + // System.out.print( PREFIX_TESTCASE + "string constructor, illegal string format (no ])..." ); + // p_si = new RasPoint( "[" + COORD_1 + "," + COORD_2 ); + // System.out.println( "point is: " + p_si ); + // if (! p_si.equals( new RasPoint( "[" + COORD_1 + "," + COORD_2 + "]" ) ) ) + // System.out.println( ERROR_TAG + "wrong point value." ); + + // System.out.print( PREFIX_TESTCASE + "string constructor, illegal string format (no ,)..." ); + // p_si = new RasPoint( "[" + COORD_1 + " " + COORD_2 + "]" ); + // System.out.println( "point is: " + p_si ); + // if (! p_si.equals( new RasPoint( "[" + COORD_1 + "," + COORD_2 + "]" ) ) ) + // System.out.println( ERROR_TAG + "wrong point value." ); + + // System.out.print( PREFIX_TESTCASE + "string constructor, illegal string format (bad int)..." ); + // p_si = new RasPoint( "[" + "abc" + "," + "xyz" + "]" ); + // System.out.println( "point is: " + p_si ); + // if (! p_si.equals( p_si ) ) + // System.out.println( ERROR_TAG + "point not equal to itself." ); + + // System.out.print( PREFIX_TESTCASE + "string constructor, illegal string format (missing int)..." ); + // p_si = new RasPoint( "[" + "," + "]" ); + // System.out.println( "point is: " + p_si ); + // if (! p_si.equals( p_si ) ) + // System.out.println( ERROR_TAG + "point not equal to itself." ); + + // 2-D constructor + System.out.print( PREFIX_TESTCASE + "2D string constructor..." ); + RasPoint p_2d = new RasPoint( "[" + COORD_1 + "," + COORD_2 + "]" ); + if (p_2d == null) + System.out.println( ERROR_TAG + "result is null." ); + else if (p_2d.dimension() != 2) + System.out.println( ERROR_TAG + "dimension is not 2 but " + p_2d.dimension() ); + else if (p_2d.item(0) != COORD_1) + System.out.println( ERROR_TAG + "item(0) returns wrong component " + p_2d.item(0) ); + else if (p_2d.item(1) != COORD_2) + System.out.println( ERROR_TAG + "item(1) returns wrong component " + p_2d.item(0) ); + else if (! p_2d.equals( p_2d ) ) + System.out.println( ERROR_TAG + "point not equal to itself." ); + else if ( p_2d.notEquals( p_2d ) ) + System.out.println( ERROR_TAG + "point notEqual to itself." ); + else + System.out.println( "OK, result=" + p_2d ); + + // 3-D constructor + System.out.print( PREFIX_TESTCASE + "3D string constructor..." ); + RasPoint p_3d = new RasPoint( "[" + COORD_1 + "," + COORD_2 + "," + COORD_3 + "]" ); + if (p_3d == null) + System.out.println( ERROR_TAG + "result is null." ); + else if (p_3d.dimension() != 3) + System.out.println( ERROR_TAG + "dimension is not 3 but " + p_3d.dimension() ); + else if (p_3d.item(2) != COORD_3) + System.out.println( ERROR_TAG + "item(2) returns wrong component " + p_3d.item(0) ); + else if (! p_3d.equals( p_3d ) ) + System.out.println( ERROR_TAG + "point not equal to itself." ); + else if ( p_3d.notEquals( p_3d ) ) + System.out.println( ERROR_TAG + "point notEqual to itself." ); + else + System.out.println( "OK, result=" + p_3d ); + + // 4-D constructor + System.out.print( PREFIX_TESTCASE + "4D string constructor..." ); + RasPoint p_4d = new RasPoint( "[" + COORD_1 + "," + COORD_2 + "," + COORD_3 + "," + COORD_4 + "]" ); + if (p_4d == null) + System.out.println( ERROR_TAG + "result is null." ); + else if (p_4d.dimension() != 4) + System.out.println( ERROR_TAG + "dimension is not 4 but " + p_4d.dimension() ); + else if (p_4d.item(3) != COORD_4) + System.out.println( ERROR_TAG + "item(3) returns wrong component " + p_4d.item(0) ); + else if (! p_4d.equals( p_4d ) ) + System.out.println( ERROR_TAG + "point not equal to itself." ); + else if ( p_4d.notEquals( p_4d ) ) + System.out.println( ERROR_TAG + "point notEqual to itself." ); + else + System.out.println( "OK, result=" + p_4d ); + + // 5-D constructor + System.out.print( PREFIX_TESTCASE + "5D string constructor..." ); + RasPoint p_5d = new RasPoint( "[" + COORD_1 + "," + COORD_2 + "," + COORD_3 + "," + COORD_4 + "," + COORD_5 + "]" ); + if (p_5d == null) + System.out.println( ERROR_TAG + "result is null." ); + else if (p_5d.dimension() != 5) + System.out.println( ERROR_TAG + "dimension is not 5 but " + p_5d.dimension() ); + else if (p_5d.item(4) != COORD_5) + System.out.println( ERROR_TAG + "item(4) returns wrong component " + p_5d.item(0) ); + else if (! p_5d.equals( p_5d ) ) + System.out.println( ERROR_TAG + "point not equal to itself." ); + else if ( p_5d.notEquals( p_5d ) ) + System.out.println( ERROR_TAG + "point notEqual to itself." ); + else + System.out.println( "OK, result=" + p_5d ); + + // copy constructor + System.out.print( PREFIX_TESTCASE + "copy constructor..." ); + RasPoint p_cp = new RasPoint( p_2d ); + if (p_cp == null) + System.out.println( ERROR_TAG + "result is null." ); + else if (p_cp.dimension() != p_2d.dimension()) + System.out.println( ERROR_TAG + "dimension mismatch." ); + else if (p_cp.item(0) != p_2d.item(0)) + System.out.println( ERROR_TAG + "item(0) returns wrong component " + p_cp.item(0) ); + else if (p_cp.item(1) != p_2d.item(1)) + System.out.println( ERROR_TAG + "item(1) returns wrong component " + p_cp.item(1) ); + else if (! p_cp.equals( p_2d ) ) + System.out.println( ERROR_TAG + "point not equal to origin." ); + else if ( p_cp.notEquals( p_2d ) ) + System.out.println( ERROR_TAG + "point notEqual to origin." ); + else + System.out.println( "OK, result=" + p_cp ); + + System.out.println( PREFIX_TESTSET + "testing constructor done.\n" ); + return; + } // testConstructor() + + /** + * test Point addition -- TO BE DONE + * any eventual exception that is not caught here is an error, and will cause an abort + **/ + static void testAdd() throws RasDimensionMismatchException, RasIndexOutOfBoundsException, RasStreamInputOverflowException + { + System.out.println( PREFIX_TESTSET + "testing add started." ); + + RasPoint p1 = new RasPoint(COORD_3,COORD_4); + RasPoint p2 = new RasPoint(COORD_3,COORD_4); + p2 = p2.add(p2); + + // test if two points are equal + boolean b1 = false; + if(p2.comparedWith(p1) == 0) + b1 = p1.equals(p2); + else + b1 = false; + System.out.println("points are equal: " + b1); + + // get the dimension of a Point + int i; + b1 = false; + if((p1.dimension() == 2) && (2 == p2.dimension())) + b1 = true; + System.out.println("dimensions of points are correct: " + b1); + + b1 = false; + p2.setItem(1, 48); + if(p2.item(1) == 48) + b1 = true; + System.out.println("read and write access of points is OK: " + b1); + + b1 = false; + p2.setTo(p2.mult(p1)); + if(p2.equals(new RasPoint(443556, 42624))) + b1 = true; + System.out.println("mult and setTo is OK: " + b1); + + b1 = false; + RasPoint ps = new RasPoint( 3 ); + ps.stream( 42 ); + if(ps.item(0) == 42) + b1 = true; + System.out.println("stream initializing of points is OK: " + b1); + + System.out.println( PREFIX_TESTSET + "testing add done.\n" ); + return; + } // testAdd() + + } // TestRasPoint diff --git a/java/rasj/test/count.sh b/java/rasj/test/count.sh new file mode 100644 index 0000000..83b7ece --- /dev/null +++ b/java/rasj/test/count.sh @@ -0,0 +1,11 @@ +#!/bin/bash + + +awk < $1 ' +BEGIN { COUNT=0; MIN=1000; MAX=0; SMALL=0; LARGE=0;} + { COUNT++; + if ($6>1000) LARGE++; else SMALL++; + if ($6>MAX) MAX = $6; + if ($6<MIN) MIN = $6; + } +END { printf("count=%d, small=%d, large=%d, min=%d, max=%d, percent=%f\n", COUNT, SMALL, LARGE, MIN, MAX, LARGE/COUNT*100 ); } ' diff --git a/java/rasj/test/httptest.java b/java/rasj/test/httptest.java new file mode 100644 index 0000000..4754ec7 --- /dev/null +++ b/java/rasj/test/httptest.java @@ -0,0 +1,53 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +package rasj.test; + +import rasj.*; +import rasj.clientcommhttp.*; + +public class httptest +{ + + public static void main(String[] args) + { + + + System.err.println("Start ..."); + RasHttpRequest test = new RasHttpRequest(); + try + { + test.execute("http://maitai.akglocal.de:8080/","SELECT img[0:200,0:200] FROM lva AS img"); + } + catch( RasQueryExecutionFailedException e) + { + System.err.println(e.getMessage()); + } + + + + + } + + + +} diff --git a/java/rasj/test/testEva.java b/java/rasj/test/testEva.java new file mode 100644 index 0000000..907afd0 --- /dev/null +++ b/java/rasj/test/testEva.java @@ -0,0 +1,229 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +package rasj.test; + +import java.util.StringTokenizer; +import java.lang.Integer; +import java.lang.Long; +import rasj.*; +import rasj.odmg.*; + +public class testEva +{ + + public static void main(String argv[]) throws RasException + { + + // Points and Intervals + ////////////////////////////////////////////// + // create a new RasPoint + RasPoint p1 = new RasPoint("[666, 777]"); + RasPoint p2 = new RasPoint(5,4); + + // test if two points are equal + boolean b1; + b1 = p1.equals(p2); + + // get the dimension of a Point + int i; + i = p1.dimension(); + + + + // create a new RasSInterval + RasSInterval s1 = new RasSInterval(100,200); + RasSInterval s2 = new RasSInterval("150:400"); + + // get upper bound + long l1; + l1 = s2.high(); + + // test if lower bound is fixed + boolean b2; + b2 = s2.isLowFixed(); + + // test if interval intersects with another interval + // (the return value shows the kind of intersection) + int j; + j = s1.intersectsWith(s2); + + + // create new RasMInterval + RasMInterval m1 = new RasMInterval("[567:3253,666:777]"); + RasMInterval m2 = new RasMInterval(4); + + // get number of cells + long l2 = 1; + RasPoint m1Ext = m1.getExtent(); + for (int dimi =0; dimi < m1Ext.dimension() ; dimi++) + { + l2 = l2 * m1Ext.item(dimi); + } + + // Types + /////////////////////////////////////////// + String s = "marray <char, 1>"; + RasType rType = RasType.getAnyType(s); + RasBaseType rb; + + if(rType.getClass().getName().equals("rasj.RasMArrayType")) + { + RasMArrayType tmp = (RasMArrayType)rType; + rb = tmp.getBaseType(); + + System.out.println(rb); + } + else + System.out.println("element of MDD Collection is no MArray."); + + boolean b3; + b3 = rType.isStructType(); + + + + // StorageLayout + /////////////////////////////////////////// + RasGMArray myMDD = new RasGMArray(new RasMInterval("[1:400,1:400]"),1); + byte[] mydata = new byte[160000]; + for(int y=0; y<400; y++) + { + for(int x=0; x<400; x++) + { + if((x>99 && x<151) || (x>299 && x<351)) + mydata[y*399+x]=100; + else + mydata[y*399+x]=0; + } + } + + myMDD.setArray(mydata); + myMDD.setObjectTypeName("GreyImage"); + + RasStorageLayout myLayout = new RasStorageLayout(); + + myLayout.setTileSize(32); + // you can either set the TileSize or the TileDomain + myLayout.setTileDomain("[1:100,1:70]"); + //myMDD.setStorageLayout(); + + + i = p2.dimension(); + b1 = p1.equals(p2); + //System.out.println(p1); + //p1.setTo(p1.mult(p2)); + + //sinterval////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + RasSInterval sint1 = new RasSInterval(100,200); + RasSInterval sint2 = new RasSInterval("150 :400 "); + RasSInterval sint3 = new RasSInterval("50:250"); + + + + sint1.setHigh(500); + sint1.setLow(400); + sint1.setLow('*'); + sint1.setHigh('*'); + + sint1.setInterval('*',500); + + l1 = sint1.low(); + l2 = sint1.high(); + b1 = sint1.isLowFixed(); + + i = sint1.intersectsWith(sint1); + + //System.out.println(sint1); + //System.out.println(l1); + //System.out.println(l2); + //System.out.println(b1); + //System.out.println(i); + + sint3 = sint3.unionOf(sint1, sint2); + sint3 = sint3.unionWith(sint2); + sint3 = sint3.addToSelf(sint2); + sint3 = sint3.createUnion(sint2); + sint3 = sint3.add(sint2); + //sint3 = sint3.differenceOf(sint2, sint1); + //sint3 = sint3.differenceWith(sint1); + sint3 = sint3.intersectionOf(sint2, sint1); + sint3 = sint3.intersectionWith(sint2); + sint3 = sint3.multWithSelf(sint2); + sint3 = sint3.createIntersection(sint2); + sint3 = sint3.mult(sint2); + sint3 = sint3.closureOf(sint2, sint1); + sint3 = sint3.closureWith(sint2); + sint3 = sint3.createClosure(sint2); + + //Minterval////////////////////////////////////////////////////////////////////////////////////////////////////////////// + RasMInterval mint1 = new RasMInterval("[567 :3253,666 :777]"); + RasMInterval mint2 = new RasMInterval(4); + + //GMarray//////////////////////////////////////////////////////////////////////////////////////////////////////////////// + RasGMArray array1 = new RasGMArray(); + RasGMArray array2 = new RasGMArray(mint1, 8); + + + byte[] bya = new byte[8]; + + + + l1 = 1; + RasPoint mint1Ext = mint1.getExtent(); + for (int dimi =0; dimi < mint1Ext.dimension() ; dimi++) + { + l1 = l1 * mint1Ext.item(dimi); + } + + array1.setTo(array2); + //bya = array2.getCell(p1); + array2.intersectionWith(mint1); + + + //Ausgabe//////////////////////////////////////////////////////////////////////////////////////////////////////////////// + System.out.println("Array1 " + array1); + System.out.println("Array2 " + array2); + + + + System.out.println("Punkt1 " + p1); + System.out.println("Punkt2 " + p2); + + System.out.println("Sinterval1 " + s1); + System.out.println("Sinterval2 " + s2); + //System.out.println("Sinterval3 " + sint3); + + System.out.println("Minterval1 " + m1); + System.out.println("Minterval2 " + m2); + + + System.out.println("i = " + i); + System.out.println("j = " + j); + System.out.println("b1 = " + b1); + System.out.println("b2 = " + b2); + System.out.println("b3 = " + b3); + System.out.println("l1 = " + l1); + System.out.println("l2 = " + l2); + //System.out.println(bya); + + } +} diff --git a/java/rasj/test/testIntervals.java b/java/rasj/test/testIntervals.java new file mode 100644 index 0000000..a06d980 --- /dev/null +++ b/java/rasj/test/testIntervals.java @@ -0,0 +1,326 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +package rasj.test; + +import java.util.StringTokenizer; +import java.lang.Integer; +import java.lang.Long; +import rasj.*; +import rasj.odmg.*; + +public class testIntervals +{ + + public static void main(String argv[]) throws RasException + { + testIntervals intervalTest = new testIntervals(); + } + + public testIntervals() + { + try + { + // Points and Intervals + ////////////////////////////////////////////// + System.out.println("\n############################ test points: "); + // create a new RasPoint + RasPoint p1 = new RasPoint("[666, 888]"); + RasPoint p2 = new RasPoint(333,444); + p2 = p2.add(p2); + + // test if two points are equal + boolean b1 = false; + if(p2.comparedWith(p1) == 0) + b1 = p1.equals(p2); + else + b1 = false; + System.out.println("points are equal: " + b1); + + // get the dimension of a Point + int i; + b1 = false; + if((p1.dimension() == 2) && (2 == p2.dimension())) + b1 = true; + System.out.println("dimensions of points are correct: " + b1); + + b1 = false; + p2.setItem(1, 48); + if(p2.item(1) == 48) + b1 = true; + System.out.println("read and write access of points is OK: " + b1); + + b1 = false; + p2.setTo(p2.mult(p1)); + if(p2.equals(new RasPoint(443556, 42624))) + b1 = true; + System.out.println("mult and setTo is OK: " + b1); + + b1 = false; + p1.stream(3); + if(p1.item(0) == 3) + b1 = true; + System.out.println("stream initializing of points is OK: " + b1); + + + // create a new RasSInterval + System.out.println("\n############################ test sintervals: "); + RasSInterval s1 = new RasSInterval(100,200); + RasSInterval s2 = new RasSInterval("150:400"); + + // get upper bound + b1 = false; + if(s2.high() == 400) + b1 = true; + System.out.println("upper bound is correct: " + b1); + + // test if lower bound is fixed + boolean b2; + b1 = false; + b1 = s2.isLowFixed(); + System.out.println("lower bound is fix: " + b1); + + // test if interval intersects with another interval + // (the return value shows the kind of intersection) + int j; + j = s1.intersectsWith(s2); + b1 = false; + if(j != -1) + b1 = true; + System.out.println("s1 intersects with s2: " + b1); + + RasSInterval sint1 = new RasSInterval(100,200); + RasSInterval sint2 = new RasSInterval("150 :400 "); + RasSInterval sint3 = new RasSInterval("50:180"); + + b1 = false; + sint1.setHigh('*'); + sint1.setLow(400); + if(sint1.low() == 400) + b1 = true; + sint1.setLow('*'); + sint1.setHigh(500); + if((sint1.high() == 500) && b1) + b1 = true; + else + b1 = false; + System.out.println("setLow and setHigh are OK: " + b1); + + sint1.setInterval('*',500); + b1 = !sint1.isLowFixed(); + b1 = sint1.isHighFixed() && b1; + System.out.println("low is open high is fixed: " + b1); + + b1 = false; + if(sint1.intersectsWith(sint1) != -1) + b1 = true; + + if(sint3.closureOf(sint2, sint1).equals(sint1) && + sint3.closureWith(sint2).equals(sint1) && + sint3.createClosure(sint2).equals(sint1)) + b1 = b1 && true; + + sint1.setInterval(90, 105); + sint2.setInterval(100, 110); + if(sint2.createDifference(sint1).equals(new RasSInterval(90, 100)) && + sint3.createIntersection(sint2).equals(new RasSInterval(100, 110))) + b1 = b1 && true; + + if(sint3.createUnion(sint2).equals(sint1) && + sint1.differenceOf(sint1, sint2).equals(new RasSInterval(90, 100)) && + sint1.differenceWith(sint2).equals(new RasSInterval(100, 110))) + b1 = b1 && true; + + if(sint3.intersectionOf(sint2, sint1).equals(new RasSInterval(100, 100)) && + sint3.intersectionWith(sint2).equals(new RasSInterval(100, 100))) + b1 = b1 && true; + + b1 = b1 && !sint3.equals(sint2); + if(sint3.unionOf(sint1, sint2).equals(new RasSInterval(90, 110)) && + sint3.unionWith(sint2).equals(new RasSInterval(90, 110))) + b1 = b1 && true; + System.out.println("operations of sintervals are correct: " + b1); + + + + // create new RasMInterval + System.out.println("\n############################ test mintervals: "); + RasMInterval mint1 = new RasMInterval("[567:3253,666:888]"); + RasMInterval mint2 = new RasMInterval("[678:4000,777:999]"); + RasMInterval mint3 = new RasMInterval("[777:900,888:1000]"); + RasMInterval mint4 = new RasMInterval(2); + b1 = false; + if((mint2.dimension() == 2) && (mint1.dimension() == 2)) + b1 = true; + System.out.println("dimensions of mintervals are correct: " + b1); + + b1 = false; + mint1 = new RasMInterval("[500:3000,600:800]"); + mint2 = new RasMInterval("[600:1000,700:750]"); + b1 = mint1.intersectsWith(mint2); + mint1 = new RasMInterval("[567:3253,666:888]"); + mint2 = new RasMInterval("[678:4000,777:999]"); + if(mint3.closureOf(mint2, mint1).toString().equals(new RasMInterval("[567:4000,666:999]").toString())) + b1 = b1 && true; + else b1 = false; + if(mint3.closureWith(mint2).toString().equals(new RasMInterval("[567:4000,666:999]").toString())) + b1 = b1 && true; + else b1 = false; + if(mint3.createClosure(mint2).toString().equals(new RasMInterval("[567:4000,666:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = new RasMInterval("[678:2000,777:888]"); + mint3 = mint3.createDifference(mint2); + if(mint3.toString().equals(new RasMInterval("[2000:4000,888:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = new RasMInterval("[678:2000,777:888]"); + mint3 = mint3.createDifference(mint2); + if(mint3.toString().equals(new RasMInterval("[2000:4000,888:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = new RasMInterval("[678:2000,777:888]"); + mint3 = mint3.createIntersection(mint2); + if(mint3.toString().equals(new RasMInterval("[678:2000,777:888]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = new RasMInterval("[678:2000,777:888]"); + mint2 = new RasMInterval("[1000:4000,750:999]"); + mint3 = mint3.createUnion(mint2); + if(mint3.toString().equals(new RasMInterval("[678:4000, 750:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint2 = new RasMInterval("[1000:4000,800:999]"); + mint1 = mint1.differenceOf(mint3, mint2); + if(mint1.toString().equals(new RasMInterval("[678:1000,750:800]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = mint3.intersectionOf(mint2, mint1); + if(mint3.toString().equals(new RasMInterval("[1000:1000,800:800]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = mint3.intersectionWith(mint2); + if(mint3.toString().equals(new RasMInterval("[1000:1000,800:800]").toString())) + b1 = b1 && true; + else b1 = false; + b1 = b1 && !mint3.equals(mint2); + mint3 = mint3.unionOf(mint1, mint2); + if(mint3.toString().equals(new RasMInterval("[678:4000,750:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint3 = mint3.unionWith(mint2); + if(mint3.toString().equals(new RasMInterval("[678:4000,750:999]").toString())) + b1 = b1 && true; + else b1 = false; + mint2 = mint2.differenceWith(mint3); + if(mint2.toString().equals(new RasMInterval("[678:1000,750:800]").toString())) + b1 = b1 && true; + else b1 = false; + System.out.println("operations of mintervals are correct: " + b1); + + // Types + /////////////////////////////////////////// + System.out.println("\n############################ test types: "); + String s = "marray <char, 1>"; + RasType rType = RasType.getAnyType(s); + RasBaseType rb; + + if(rType.getClass().getName().equals("rasj.RasMArrayType")) + { + RasMArrayType tmp = (RasMArrayType)rType; + rb = tmp.getBaseType(); + + System.out.println("OK"); + } + else + System.out.println("element of MDD Collection is no MArray."); + + boolean b3; + b3 = !rType.isStructType(); + System.out.println(b3); + + + // StorageLayout + /////////////////////////////////////////// + System.out.println("\n############################ test storage layout: "); + RasGMArray myMDD = new RasGMArray(new RasMInterval("[1:400,1:400]"),1); + byte[] mydata = new byte[160000]; + for(int y=0; y<400; y++) + { + for(int x=0; x<400; x++) + { + if((x>99 && x<151) || (x>299 && x<351)) + mydata[y*399+x]=100; + else + mydata[y*399+x]=0; + } + } + + myMDD.setArray(mydata); + myMDD.setObjectTypeName("GreyImage"); + + RasStorageLayout myLayout = new RasStorageLayout(); + + myLayout.setTileDomain("[1:100,1:70]"); + // you can either set the TileSize or the TileDomain + myLayout.setTileSize(32); + myMDD.setStorageLayout(myLayout); + if(myMDD.getStorageLayout().getTileSize() == 32) + System.out.println("OK"); + + + //GMarray//////////////////////////////////////////////////////////////////////////////////////////////////////////////// + RasGMArray array1 = new RasGMArray(); + RasGMArray array2 = new RasGMArray(mint1, 8); + + myMDD.getCell(new RasPoint(1,1)); + + System.out.println("OK"); + + + //Ausgabe//////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /* + System.out.println("Array1 " + array1); + System.out.println("Array2 " + array2); + + System.out.println("Punkt1 " + p1); + System.out.println("Punkt2 " + p2); + + System.out.println("Sinterval1 " + s1); + System.out.println("Sinterval2 " + s2); + System.out.println("Sinterval3 " + sint3); + + System.out.println("j = " + j); + //System.out.println("b1 = " + b1); + //System.out.println("b2 = " + b2); + System.out.println("b3 = " + b3); + */ + + + } + catch (RasException e) + { + System.out.println("!!!!!!!!!!!!!!!!!!!!While testing!!!!!!!!!!!!!!!!!!"); + System.out.println("An RasException has occurred: " + e.getMessage()); + } + } +} diff --git a/java/rasj/test/testMArrays.java b/java/rasj/test/testMArrays.java new file mode 100644 index 0000000..272ece1 --- /dev/null +++ b/java/rasj/test/testMArrays.java @@ -0,0 +1,871 @@ +package rasj.test; + +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +*/ +/** *********************************************************** + * <pre> + * + * PURPOSE: class for testing special MArrays + * + * + * + * COMMENTS: + * + * </pre> + *********************************************************** */ + +import java.io.*; +import java.net.*; +import rasj.clientcommhttp.*; +import rasj.odmg.*; +import org.odmg.*; +import rasj.*; +import java.util.*; + +/** + * class for testing special MArrays + * for testing please enable test data output in toString method of RASGMArray + * @version $$ + */ +public class testMArrays +{ + public static void main(String[] args) + { + String serv = "localhost"; + String base = "RASBASE"; + String coll = "test"; + + for (int i=args.length-1; i>=0; i--) + { + //System.out.println(args[i]); + if (args[i].equals("-server")) + serv = args[i+1]; + if (args[i].equals("-database")) + base = args[i+1]; + if (args[i].equals("-collection")) + coll = args[i+1]; + } + //System.out.println(server+base+coll); + testMArrays marrayTest = new testMArrays(serv); + + } + + public testMArrays(String server) + { + DBag resultBag = null; + Object result = null; + Transaction myTa = null; + Database myDb = null; + OQLQuery myQu = null; + + boolean equal = false; + + try + { + System.out.println("### Testing MArrays: ..."); + Implementation myApp = new RasImplementation("http://"+server+":7001"); + myDb = myApp.newDatabase(); + + System.out.println("Opening database ..."); + myDb.open("RASBASE", Database.OPEN_READ_WRITE); + myTa = myApp.newTransaction(); + + int width, height, len; + width = 18; + height = 18; + len = (width+1)*(height+1); + RasMInterval domain = new RasMInterval("[0:"+width+",0:"+height+"]"); + RasMInterval domain2 = new RasMInterval("[1:3,1:3]"); + RasStorageLayout stl = new RasStorageLayout(); + stl.setTileSize(128); + + + /** + * test the GMArray + */ + System.out.println("\n\n### Testing GMArray with OID: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + try + { + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + } + catch(ODMGException e) + { + myTa.abort(); + System.err.println("Collection test does not exist: " + e.getMessage()); + } + + myQu.create("create collection test GreySet"); + RasGMArray mddConst = new RasGMArray(domain, 1, stl); + //RasGMArray mddConst = new RasGMArray(domain, 1); + byte[] data = new byte[len]; + mddConst.setObjectTypeName("GreyImage"); + + // test: get new OID from the server for GMArray and insert + System.out.println("new OID from server: " + myApp.getObjectId(mddConst)); + + for(int j = 0; j < data.length; j++) + data[j] = (byte)j; + + mddConst.setArray(data); + /* + System.out.println("\nbyte array: "); + for(int j=0; j<mddConst.getArray().length; j++) + { + System.out.print(" "+ mddConst.getArray()[j]); + } + */ + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddConst); + myQu.bind(mddConst); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + equal = true; + for(int j=0; j<mddConst.getArray().length; j++) + { + if(mddConst.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + if(!(myApp.getObjectId(mddConst).toString()).equals(myApp.getObjectId((RasGMArray)result).toString())) + equal = false; + System.out.println("result mdd: " + ((RasGMArray)mddConst).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + } + System.out.println("inserted and selected GMArray and OIDs are equal: " + equal); + //System.out.println("All results for test GMArray"); + } + + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasGMArray mddConst2 = new RasGMArray(mddConst); + mddConst2.setArray(data); + //System.out.println("\nbyte array2: "); + data = null; + equal = true; + for(int j=0; j<mddConst.getArray().length; j++) + { + //System.out.print(" "+ mddConst2.getArray()[j]); + if(mddConst.getArray()[j] != mddConst2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + + /** + * test the MArrayByte + */ + System.out.println("\n\n### Testing MArrayByte: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test GreySet"); + RasMArrayByte mddByte = new RasMArrayByte(domain, stl); + byte[] dataByte = new byte[len]; + mddByte.setObjectTypeName("GreyImage"); + + for(int j = 0; j < dataByte.length; j++) + dataByte[j] = (byte)j; + + mddByte.setArray(dataByte); + + //System.out.println("\nbyte array: "); + //for(int j=0; j<mddByte.getArray().length; j++) + //{ + //System.out.print(" "+ mddByte.getArray()[j]); + //} + + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddByte); + myQu.bind(mddByte); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + System.out.println("result mdd: " + ((RasGMArray)mddByte).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + equal = true; + for(int j=0; j<mddByte.getArray().length; j++) + { + if(mddByte.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + } + //System.out.println("All results for MArrayByte"); + System.out.println("inserted and selected MArrayByte are equal: " + equal); + } + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayByte mddByte2 = new RasMArrayByte(mddByte); + mddByte2.setArray(dataByte); + //System.out.println("\nbyte array2: "); + dataByte = null; + equal = true; + for(int j=0; j<mddByte.getArray().length; j++) + { + //System.out.print(" "+ mddByte2.getArray()[j]); + if(mddByte.getArray()[j] != mddByte2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + + /** + * test the MArrayInteger + */ + System.out.println("\n\n### Testing MArrayInteger: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test UShortSet"); + RasMArrayInteger mddInteger = new RasMArrayInteger(domain, stl); + int[] dataInteger = new int[len]; + //byte[] dataInteger = new byte[144]; + mddInteger.setObjectTypeName("UShortImage"); + + for(int j = 0; j < dataInteger.length; j++) + dataInteger[j] = j; + + mddInteger.setArray(dataInteger); + + //System.out.println("\nbyte array: "); + //for(int j=0; j<mddInteger.getArray().length; j++) + //{ + //System.out.print(" "+ mddInteger.getArray()[j]); + //} + + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddInteger); + myQu.bind(mddInteger); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + System.out.println("result mdd: " + ((RasGMArray)mddInteger).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + equal = true; + for(int j=0; j<mddInteger.getArray().length; j++) + { + if(mddInteger.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + } + //System.out.println("All results for MArrayInteger"); + System.out.println("inserted and selected MArrayInteger are equal: " + equal); + } + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayInteger mddInteger2 = new RasMArrayInteger(mddInteger); + mddInteger2.setArray(dataInteger); + dataInteger = null; + equal = true; + for(int j=0; j<mddInteger2.getArray().length; j++) + { + //System.out.print(" "+ mddInteger2.getArray()[j]); + if(mddInteger.getArray()[j] != mddInteger2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + + /* + System.out.println("\nspecial array2: "); + for(int j=0; j<mddInteger2.getIntArray().length; j++) + { + System.out.print(" "+ mddInteger2.getIntArray()[j]); + } + */ + + /** + * test the MArrayDouble + */ + System.out.println("\n\n### Testing MArrayDouble: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test DoubleSet"); + RasMArrayDouble mddDouble = new RasMArrayDouble(domain, stl); + double[] dataDouble = new double[len]; + //byte[] dataDouble = new byte[288]; + mddDouble.setObjectTypeName("DoubleImage"); + + for(double j = 0; j < dataDouble.length; j++) + dataDouble[(int)j] = j; + + mddDouble.setArray(dataDouble); + + //System.out.println("\nbyte array: "); + //for(int j=0; j<mddDouble.getArray().length; j++) + //{ + //System.out.print(" "+ mddDouble.getArray()[j]); + //} + + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddDouble); + myQu.bind(mddDouble); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + equal = true; + for(int j=0; j<mddDouble.getDoubleArray().length; j++) + { + if(mddDouble.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + System.out.println("result mdd: " + ((RasGMArray)mddDouble).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + } + //System.out.println("All results for MArrayDouble"); + System.out.println("inserted and selected MArrayDouble are equal: " + equal); + } + + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayDouble mddDouble2 = new RasMArrayDouble(mddDouble); + mddDouble2.setArray(dataDouble); + //System.out.println("byte array2: "); + dataDouble = null; + equal = true; + for(int j=0; j<mddDouble2.getArray().length; j++) + { + //System.out.print(" "+ mddDouble2.getArray()[j]); + if(mddDouble.getArray()[j] != mddDouble2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + + /* + System.out.println("\nspecial array2: "); + for(int j=0; j<mddDouble2.getDoubleArray().length; j++) + { + System.out.print(" "+ mddDouble2.getDoubleArray()[j]); + } + */ + + /** + * test the MArrayFloat + */ + System.out.println("\n\n### Testing MArrayFloat: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test FloatSet"); + RasMArrayFloat mddFloat = new RasMArrayFloat(domain, stl); + float[] dataFloat = new float[len]; + //byte[] dataFloat = new byte[144]; + mddFloat.setObjectTypeName("FloatImage"); + + for(float j = 0; j < dataFloat.length; j++) + dataFloat[(int)j] = j; + + mddFloat.setArray(dataFloat); + + //System.out.println("\nbyte array: "); + //for(int j=0; j<mddFloat.getArray().length; j++) + //{ + //System.out.print(" "+ mddFloat.getArray()[j]); + //} + + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddFloat); + myQu.bind(mddFloat); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + equal = true; + for(int j=0; j<mddFloat.getArray().length; j++) + { + if(mddFloat.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + System.out.println("result mdd: " + ((RasGMArray)mddFloat).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + } + //System.out.println("All results for MArrayFloat"); + System.out.println("inserted and selected MArrayFloat are equal: " + equal); + } + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayFloat mddFloat2 = new RasMArrayFloat(mddFloat); + mddFloat2.setArray(dataFloat); + //System.out.println("\nbyte array2: "); + dataFloat = null; + equal = true; + for(int j=0; j<mddFloat2.getArray().length; j++) + { + //System.out.print(" "+ mddFloat2.getArray()[j]); + if(mddFloat.getArray()[j] != mddFloat2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + /* + System.out.println("\nspecial array2: "); + for(int j=0; j<mddFloat2.getFloatArray().length; j++) + { + System.out.print(" "+ mddFloat2.getFloatArray()[j]); + } + */ + + /** + * test the MArrayShort + */ + System.out.println("\n\n### Testing MArrayShort: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test ShortSet"); + RasMArrayShort mddShort = new RasMArrayShort(domain, stl); + //RasMArrayShort mddShort4 = new RasMArrayShort(domain, stl); + //RasMArrayShort mddShort3 = new RasMArrayShort(domain, stl); + short[] dataShort = new short[len]; + //short[] dataShort4 = new short[len]; + //short[] dataShort3 = new short[len]; + //byte[] dataShort = new byte[72]; + mddShort.setObjectTypeName("ShortImage"); + //mddShort4.setObjectTypeName("ShortImage"); + //mddShort3.setObjectTypeName("ShortImage"); + + //System.out.println("new OID from server: " + myApp.getObjectId(mddShort)); + //System.out.println("new OID from server: " + myApp.getObjectId(mddShort4)); + for(int j = 0; j < dataShort.length; j++) + dataShort[j] = (short)j; + + //for(int j = 0; j < dataShort.length; j++) + //dataShort[j] = 1; + //for(int j = 0; j < dataShort4.length; j++) + //dataShort4[j] = 2; + //for(int j = 0; j < dataShort3.length; j++) + //dataShort3[j] = 3; + + + mddShort.setArray(dataShort); + //mddShort4.setArray(dataShort4); + //mddShort3.setArray(dataShort3); + /* + System.out.println("\nbyte array: "); + for(int j=0; j<mddShort.getArray().length; j++) + { + System.out.print(" "+ mddShort.getArray()[j]); + } + */ + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + myQu = myApp.newOQLQuery(); + //System.out.println("\ncollection created"); + //myQu.create("insert into test values $1"); + myQu.create("insert into test values $1"); + //System.out.println("mdd before sending: " + mddShort); + //myQu.bind("test"); + myQu.bind(mddShort); + //myQu.bind(mddShort4); + //myQu.bind(mddShort3); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + /* + myTa.begin(); + myQu = myApp.newOQLQuery(); + myQu.create("insert into test values $1"); + myQu.bind(mddShort4); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + myTa.begin(); + myQu = myApp.newOQLQuery(); + myQu.create("insert into test values $1"); + myQu.bind(mddShort3); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + */ + //System.out.println("collection inserted"); + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + equal = true; + for(int j=0; j<mddShort.getArray().length; j++) + { + if(mddShort.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + System.out.println("result mdd: " + ((RasGMArray)mddShort).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + } + //System.out.println("All results for MArrayShort"); + System.out.println("inserted and selected MArrayShort are equal: " + equal); + } + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayShort mddShort2 = new RasMArrayShort(mddShort); + mddShort2.setArray(dataShort); + //System.out.println("\nbyte array2: "); + dataShort = null; + equal = true; + for(int j=0; j<mddShort2.getArray().length; j++) + { + //System.out.print(" "+ mddShort2.getArray()[j]); + if(mddShort.getArray()[j] != mddShort2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + /* + System.out.println("\nspecial array2: "); + for(int j=0; j<mddShort2.getShortArray().length; j++) + { + System.out.print(" "+ mddShort2.getShortArray()[j]); + } + */ + + /** + * test the MArrayLong + */ + System.out.println("\n\n### Testing MArrayLong: ################################################"); + myQu = myApp.newOQLQuery(); + + myQu.create("drop collection test"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection dropped"); + + myQu.create("create collection test ULongSet"); + RasMArrayLong mddLong = new RasMArrayLong(domain, stl); + long[] dataLong = new long[len]; + //byte[] dataLong = new byte[288]; + mddLong.setObjectTypeName("ULongImage"); + + for(long j = 0; j < dataLong.length; j++) + dataLong[(int)j] = j; + mddLong.setArray(dataLong); + + /* + System.out.println("\nbyte array: "); + for(int j=0; j<mddLong.getArray().length; j++) + { + System.out.print(" "+ mddLong.getArray()[j]); + } + */ + + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("\ncollection created"); + myQu.create("insert into test values $1 "); + + //System.out.println("mdd before sending: " + mddLong); + myQu.bind(mddLong); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection inserted"); + + myQu = myApp.newOQLQuery(); + myQu.create("select img from test as img"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + //System.out.println("collection selected"); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + equal = true; + for(int j=0; j<((RasGMArray)result).getArray().length; j++) + { + if(mddLong.getArray()[j] != ((RasGMArray)result).getArray()[j]) + equal = false; + } + System.out.println("result mdd: " + ((RasGMArray)mddLong).toTestString()); + System.out.println("result mdd: " + ((RasGMArray)result).toTestString()); + } + //System.out.println("All results for MArrayLong"); + System.out.println("inserted MArrayInteger and selected MArrayLong are equal: " + equal); + } + + // testing copy constructor + System.out.println("### Testing copy constructor:"); + RasMArrayLong mddLong2 = new RasMArrayLong(mddLong); + mddLong2.setArray(dataLong); + //System.out.println("\nbyte array2: "); + dataLong = null; + equal = true; + for(int j=0; j<mddLong2.getArray().length; j++) + { + //System.out.print(" "+ mddLong2.getArray()[j]); + if(mddLong.getArray()[j] != mddLong2.getArray()[j]) + equal = false; + } + System.out.println("Copy constructor is OK: " + equal); + + System.out.println("\nspecial array: "); + for(int j=0; j<((RasMArrayLong)result).getLongArray().length; j++) + { + System.out.print(" "+ ((RasMArrayLong)result).getLongArray()[j]); + } + + + /** + * testing intersection + */ + System.out.println("\n\n### Testing intersection:"); + mddConst2.intersectionWith(domain2); + mddByte2.intersectionWith(domain2); + mddDouble2.intersectionWith(domain2); + mddFloat2.intersectionWith(domain2); + mddInteger2.intersectionWith(domain2); + mddLong2.intersectionWith(domain2); + mddShort2.intersectionWith(domain2); + System.out.println("OK\n"); + + /** + * testing OIDs + */ + myQu = myApp.newOQLQuery(); + myQu.create("SELECT oid(img) FROM test AS img"); + //myQu.create("SELECT img FROM test AS img where (oid(img)=231425)"); + myTa.begin(); + resultBag = (DBag)myQu.execute(); + myTa.commit(); + if (resultBag != null) + { + Iterator iter = resultBag.iterator(); + while (iter.hasNext()) + { + result = iter.next(); + //System.out.println("OID: " + result); + } + //System.out.println("All results"); + + } + + /** + * get new OID + */ + System.out.println("### Testing OIDs:"); + myTa.begin(); + myApp.getObjectId(new RasGMArray()); + myTa.commit(); + + System.out.println( "Closing database ..." ); + myDb.close(); + + // get new OID without open TA + RasGMArray gmar = new RasGMArray(); + equal = true; + if(!myApp.getObjectId(gmar).equals(gmar.getOID().toString())) + equal = false; + System.out.println("same OID on client and server side: " + equal); + + } + catch (RasException e) + { + System.out.println("!!!!!!!!!!!!!!!!!!!!While testing!!!!!!!!!!!!!!!!!!"); + System.out.println("An RasException has occurred: " + e.getMessage()); + System.out.println("Try to abort the transaction ..."); + if(myTa != null) myTa.abort(); + + try + { + System.out.println("Try to close the database ..."); + if(myDb != null) myDb.close(); + } + catch ( org.odmg.ODMGException exp ) + { + System.err.println("Could not close the database: " + exp.getMessage()); + } + } + catch (RasRuntimeException e) + { + System.out.println("!!!!!!!!!!!!!!!!!!!!While testing!!!!!!!!!!!!!!!!!!"); + System.out.println("An RasRuntimeException has occurred: " + e.getMessage()); + System.out.println("Try to abort the transaction ..."); + if(myTa != null) myTa.abort(); + + try + { + System.out.println("Try to close the database ..."); + if(myDb != null) myDb.close(); + } + catch ( org.odmg.ODMGException exp ) + { + System.err.println("Could not close the database: " + exp.getMessage()); + } + } + catch (org.odmg.ODMGException e) + { + System.out.println("!!!!!!!!!!!!!!!!!!!!While testing!!!!!!!!!!!!!!!!!!"); + System.out.println("An ODMGException has occurred: " + e.getMessage()); + System.out.println("Try to abort the transaction ..."); + if(myTa != null) myTa.abort(); + + try + { + System.out.println("Try to close the database ..."); + if(myDb != null) myDb.close(); + } + catch ( org.odmg.ODMGException exp ) + { + System.err.println("Could not close the database: " + exp.getMessage()); + } + } + System.out.println( "Done." ); + + } +} + |