aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/test/java/at/gv
diff options
context:
space:
mode:
authorChristian Maierhofer <cmaierhofer@iaik.tugraz.at>2016-04-27 16:16:44 +0200
committerChristian Maierhofer <cmaierhofer@iaik.tugraz.at>2016-04-27 16:16:44 +0200
commit6f353de9f09b26440f67f62ba8186ae82f16adb5 (patch)
treed8dbc3e91f46daca7252ceaabf355c3e25b2a62e /id/server/idserverlib/src/test/java/at/gv
parent8da90c1f897736d2d2237efedd2b6a3ac362af2d (diff)
downloadmoa-id-spss-6f353de9f09b26440f67f62ba8186ae82f16adb5.tar.gz
moa-id-spss-6f353de9f09b26440f67f62ba8186ae82f16adb5.tar.bz2
moa-id-spss-6f353de9f09b26440f67f62ba8186ae82f16adb5.zip
Added some tests for redis
Diffstat (limited to 'id/server/idserverlib/src/test/java/at/gv')
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/DummyTransactionStorage.java12
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/DBTransactionStorageTest.java122
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/RedisTransactionMultiThreadTest.java130
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/RedisTransactionStorageTest.java116
4 files changed, 380 insertions, 0 deletions
diff --git a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/DummyTransactionStorage.java b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/DummyTransactionStorage.java
index 9f1fc5f2d..ab08c0f5c 100644
--- a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/DummyTransactionStorage.java
+++ b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/DummyTransactionStorage.java
@@ -131,5 +131,17 @@ public class DummyTransactionStorage implements ITransactionStorage {
return null;
}
+ @Override
+ public Object getAssertionStore(String key) throws MOADatabaseException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void putAssertionStore(Object element) throws MOADatabaseException {
+ // TODO Auto-generated method stub
+
+ }
+
} \ No newline at end of file
diff --git a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/DBTransactionStorageTest.java b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/DBTransactionStorageTest.java
new file mode 100644
index 000000000..4b7f61ef5
--- /dev/null
+++ b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/DBTransactionStorageTest.java
@@ -0,0 +1,122 @@
+package at.gv.egovernment.moa.id.storage.test;
+
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
+import at.gv.egovernment.moa.id.storage.DBTransactionStorage;
+import at.gv.egovernment.moa.id.storage.ITransactionStorage;
+import at.gv.egovernment.moa.util.Constants;
+import at.gv.util.DOMUtils;
+
+public class DBTransactionStorageTest {
+
+ public static void main (String[] args) throws SAXException, IOException, ParserConfigurationException, MOADatabaseException{
+ DBTransactionStorageTest t = new DBTransactionStorageTest();
+ t.test();
+ }
+
+ @Autowired
+ DBTransactionStorage rts;
+
+ public DBTransactionStorageTest(){
+
+ }
+
+
+ public void test() throws SAXException, IOException, ParserConfigurationException, MOADatabaseException{
+
+
+ ApplicationContext context = new FileSystemXmlApplicationContext("src/test/java/testBeans.xml");
+
+
+ String requestString =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
+ "<samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" RequestID=\"123456\" MajorVersion=\"1\" MinorVersion=\"0\" IssueInstant=\"2003-02-13T13:59:00\">" +
+ "<samlp:AssertionArtifact>WRONGARTIFACT</samlp:AssertionArtifact>" +
+ "</samlp:Request>";
+ Element request = DOMUtils.parseDocument(requestString, false, Constants.ALL_SCHEMA_LOCATIONS, null).getDocumentElement();
+
+ ITransactionStorage rts = (ITransactionStorage) context.getBean("DBTransactionStorage");
+ //GenericToStringSerializer redisStringSerializer = (GenericToStringSerializer) context.getBean("valueObjectSerializer");
+
+ // rts.getTemplate().setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
+ // rts.getTemplate().setHashValueSerializer(new GenericToStringSerializer<Object>(Object.class));
+
+ int cnt = 10;
+ int averageCnt = 10;
+ long putTime = 0, getTime = 0, changeTime = 0, removeTime = 0;
+ long total = 0;
+ for(int a=0;a<averageCnt;a++){
+ long totalPerRound = 0;
+
+ System.out.println("Starting MySql store operation.");
+ long start = System.currentTimeMillis();
+ for(int i=0; i<cnt;i++)
+ rts.put("test"+i, request,-1);
+ long end = System.currentTimeMillis();
+ putTime += end-start;
+ System.out.println("MySql store operation done in "+(end-start)+" ms.");
+ totalPerRound+=(end-start);
+
+ Element test;
+ System.out.println("Starting MySql get operation.");
+ start = System.currentTimeMillis();
+ for(int i=0; i<cnt;i++)
+ test = (Element)rts.get("test"+i);
+ end = System.currentTimeMillis();
+ getTime += end-start;
+ System.out.println("MySql get operation done in "+(end-start)+" ms.");
+ totalPerRound+=(end-start);
+ //Element test = (Element)rts.get("test0");
+ //System.out.println("Read Element from Redis Store: "+test.getTextContent());
+
+ String requestString2 =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
+ "<samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" RequestID=\"test_new\" MajorVersion=\"1\" MinorVersion=\"0\" IssueInstant=\"2003-02-13T13:59:00\">" +
+ "<samlp:AssertionArtifact>WRONGARTIFACT</samlp:AssertionArtifact>" +
+ "</samlp:Request>";
+ Element request2 = DOMUtils.parseDocument(requestString2, false, Constants.ALL_SCHEMA_LOCATIONS, null).getDocumentElement();
+
+ System.out.println("Starting MySql change operation.");
+ start = System.currentTimeMillis();
+ for(int i=0; i<cnt;i++)
+ rts.changeKey("test"+i, "test_new"+i, request2);
+ end = System.currentTimeMillis();
+ changeTime += end-start;
+ System.out.println("MySql change operation done in "+(end-start)+" ms.");
+ totalPerRound+=(end-start);
+
+
+
+ System.out.println("Starting MySql remove operation.");
+ start = System.currentTimeMillis();
+ for(int i=0; i<cnt;i++)
+ rts.remove("test_new"+i);
+ end = System.currentTimeMillis();
+ removeTime += end-start;
+ System.out.println("MySql remove operation done in "+(end-start)+" ms.");
+ totalPerRound+=(end-start);
+ total+=totalPerRound;
+
+ System.out.println("Redis Total Time in this round: "+totalPerRound+" ms.");
+ System.out.println("______________________________________________________");
+ }
+ System.out.println("______________________________________________________");
+ System.out.println("Redis average get time over " + averageCnt +" rounds: "+getTime/averageCnt+" ms.");
+ System.out.println("Redis average put time over " + averageCnt +" rounds: "+putTime/averageCnt+" ms.");
+ System.out.println("Redis average change time over " + averageCnt +" rounds: "+changeTime/averageCnt+" ms.");
+ System.out.println("Redis average remove time over " + averageCnt +" rounds: "+removeTime/averageCnt+" ms.");
+ System.out.println("Redis average total time over " + averageCnt +" rounds: "+total/averageCnt+" ms.");
+ ((ConfigurableApplicationContext)context).close();
+ }
+
+}
diff --git a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/RedisTransactionMultiThreadTest.java b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/RedisTransactionMultiThreadTest.java
new file mode 100644
index 000000000..60b55f497
--- /dev/null
+++ b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/RedisTransactionMultiThreadTest.java
@@ -0,0 +1,130 @@
+package at.gv.egovernment.moa.id.storage.test;
+
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+import org.springframework.core.task.TaskExecutor;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
+import at.gv.egovernment.moa.id.storage.RedisTransactionStorage;
+import at.gv.egovernment.moa.util.Constants;
+import at.gv.util.DOMUtils;
+
+public class RedisTransactionMultiThreadTest {
+
+ private ApplicationContext context;
+
+ public RedisTransactionMultiThreadTest() throws SAXException, IOException, ParserConfigurationException, MOADatabaseException{
+ this.context = new FileSystemXmlApplicationContext("src/test/java/testBeans.xml");
+ TaskExecutor te = (TaskExecutor) context.getBean("taskExecutor");
+
+ for(int i=0;i<50;i++){
+ te.execute(new RedisTask("Task"+i));
+ }
+
+
+ }
+
+ public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, MOADatabaseException{
+
+ RedisTransactionMultiThreadTest t = new RedisTransactionMultiThreadTest();
+ System.out.println("End");
+
+// String requestString =
+// "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
+// "<samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" RequestID=\"123456\" MajorVersion=\"1\" MinorVersion=\"0\" IssueInstant=\"2003-02-13T13:59:00\">" +
+// "<samlp:AssertionArtifact>WRONGARTIFACT</samlp:AssertionArtifact>" +
+// "</samlp:Request>";
+// Element request = DOMUtils.parseDocument(requestString, false, Constants.ALL_SCHEMA_LOCATIONS, null).getDocumentElement();
+//
+//
+//
+//
+// RedisTransactionStorage rts = (RedisTransactionStorage) context.getBean("TransactionStorage");
+// //GenericToStringSerializer redisStringSerializer = (GenericToStringSerializer) context.getBean("valueObjectSerializer");
+//
+//// rts.getTemplate().setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
+//// rts.getTemplate().setHashValueSerializer(new GenericToStringSerializer<Object>(Object.class));
+//
+//
+// rts.put("test", request,-1);
+// System.out.println("Redis store operation done!");
+//
+// Element test = (Element)rts.get("test");
+// System.out.println("Read Element from Redis Store: "+test.getTextContent());
+//
+// String requestString2 =
+// "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
+// "<samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" RequestID=\"test_new\" MajorVersion=\"1\" MinorVersion=\"0\" IssueInstant=\"2003-02-13T13:59:00\">" +
+// "<samlp:AssertionArtifact>WRONGARTIFACT</samlp:AssertionArtifact>" +
+// "</samlp:Request>";
+// Element request2 = DOMUtils.parseDocument(requestString2, false, Constants.ALL_SCHEMA_LOCATIONS, null).getDocumentElement();
+//
+//
+// rts.changeKey("test", "test_new", request2);
+//
+// rts.remove("test");
+// rts.remove("test_new");
+//
+// ((ConfigurableApplicationContext)context).close();
+ }
+
+ private class RedisTask implements Runnable {
+
+ private String message;
+
+ public RedisTask(String message) throws SAXException, IOException, ParserConfigurationException, MOADatabaseException {
+
+ this.message = message;
+
+
+
+ }
+
+ public void run() {
+ String requestString =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
+ "<samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" RequestID=\"123456\" MajorVersion=\"1\" MinorVersion=\"0\" IssueInstant=\"2003-02-13T13:59:00\">" +
+ "<samlp:AssertionArtifact>WRONGARTIFACT</samlp:AssertionArtifact>" +
+ "</samlp:Request>";
+
+ Element request = null;
+ try {
+ request = DOMUtils.parseDocument(requestString, false, Constants.ALL_SCHEMA_LOCATIONS, null).getDocumentElement();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return;
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return;
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return;
+ }
+
+ RedisTransactionStorage rts = (RedisTransactionStorage) context.getBean("RedisTransactionStorage");
+
+ try {
+ rts.put(message, request,-1);
+ rts.changeKey(message, message+"n", request);
+ } catch (MOADatabaseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return;
+ }
+ System.out.println("Done with task "+message);
+ }
+
+ }
+
+}
diff --git a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/RedisTransactionStorageTest.java b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/RedisTransactionStorageTest.java
new file mode 100644
index 000000000..e957ffe05
--- /dev/null
+++ b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/storage/test/RedisTransactionStorageTest.java
@@ -0,0 +1,116 @@
+package at.gv.egovernment.moa.id.storage.test;
+
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
+import at.gv.egovernment.moa.id.storage.DBTransactionStorage;
+import at.gv.egovernment.moa.id.storage.RedisTransactionStorage;
+import at.gv.egovernment.moa.util.Constants;
+import at.gv.util.DOMUtils;
+
+public class RedisTransactionStorageTest {
+
+
+ public RedisTransactionStorageTest(){
+
+ }
+
+ public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException, MOADatabaseException{
+
+
+ ApplicationContext context = new FileSystemXmlApplicationContext("src/test/java/testBeans.xml");
+
+
+ String requestString =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
+ "<samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" RequestID=\"123456\" MajorVersion=\"1\" MinorVersion=\"0\" IssueInstant=\"2003-02-13T13:59:00\">" +
+ "<samlp:AssertionArtifact>WRONGARTIFACT</samlp:AssertionArtifact>" +
+ "</samlp:Request>";
+ Element request = DOMUtils.parseDocument(requestString, false, Constants.ALL_SCHEMA_LOCATIONS, null).getDocumentElement();
+
+ RedisTransactionStorage rts = (RedisTransactionStorage) context.getBean("RedisTransactionStorage");
+ //GenericToStringSerializer redisStringSerializer = (GenericToStringSerializer) context.getBean("valueObjectSerializer");
+
+ // rts.getTemplate().setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
+ // rts.getTemplate().setHashValueSerializer(new GenericToStringSerializer<Object>(Object.class));
+
+ int cnt = 100;
+ int averageCnt = 10;
+ long putTime = 0, getTime = 0, changeTime = 0, removeTime = 0;
+ long total = 0;
+ for(int a=0;a<averageCnt;a++){
+ long totalPerRound = 0;
+
+ System.out.println("Starting Redis store operation.");
+ long start = System.currentTimeMillis();
+ for(int i=0; i<cnt;i++)
+ rts.put("test"+i, request,-1);
+ long end = System.currentTimeMillis();
+ putTime += end-start;
+ System.out.println("Redis store operation done in "+(end-start)+" ms.");
+ totalPerRound+=(end-start);
+
+ Element test;
+ System.out.println("Starting Redis get operation.");
+ start = System.currentTimeMillis();
+ for(int i=0; i<cnt;i++)
+ test = (Element)rts.get("test"+i);
+ end = System.currentTimeMillis();
+ getTime += end-start;
+ System.out.println("Redis get operation done in "+(end-start)+" ms.");
+ totalPerRound+=(end-start);
+ //Element test = (Element)rts.get("test0");
+ //System.out.println("Read Element from Redis Store: "+test.getTextContent());
+
+ String requestString2 =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
+ "<samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" RequestID=\"test_new\" MajorVersion=\"1\" MinorVersion=\"0\" IssueInstant=\"2003-02-13T13:59:00\">" +
+ "<samlp:AssertionArtifact>WRONGARTIFACT</samlp:AssertionArtifact>" +
+ "</samlp:Request>";
+ Element request2 = DOMUtils.parseDocument(requestString2, false, Constants.ALL_SCHEMA_LOCATIONS, null).getDocumentElement();
+
+ System.out.println("Starting Redis change operation.");
+ start = System.currentTimeMillis();
+ for(int i=0; i<cnt;i++)
+ rts.changeKey("test"+i, "test_new"+i, request2);
+ end = System.currentTimeMillis();
+ changeTime += end-start;
+ System.out.println("Redis change operation done in "+(end-start)+" ms.");
+ totalPerRound+=(end-start);
+
+
+
+ System.out.println("Starting Redis remove operation.");
+ start = System.currentTimeMillis();
+ for(int i=0; i<cnt;i++)
+ rts.remove("test_new"+i);
+ end = System.currentTimeMillis();
+ removeTime += end-start;
+ System.out.println("Redis remove operation done in "+(end-start)+" ms.");
+ totalPerRound+=(end-start);
+ total+=totalPerRound;
+
+ System.out.println("Redis Total Time in this round: "+totalPerRound+" ms.");
+ System.out.println("______________________________________________________");
+ }
+ System.out.println("______________________________________________________");
+ System.out.println("Redis average get time over " + averageCnt +" rounds: "+getTime/averageCnt+" ms.");
+ System.out.println("Redis average put time over " + averageCnt +" rounds: "+putTime/averageCnt+" ms.");
+ System.out.println("Redis average change time over " + averageCnt +" rounds: "+changeTime/averageCnt+" ms.");
+ System.out.println("Redis average remove time over " + averageCnt +" rounds: "+removeTime/averageCnt+" ms.");
+ System.out.println("Redis average total time over " + averageCnt +" rounds: "+total/averageCnt+" ms.");
+
+ ((ConfigurableApplicationContext)context).close();
+
+
+ }
+
+}