Sandbox-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
April 2010
- 1 participants
- 5 discussions
r407 - in testTopiaPostgresError/trunk: . src/main/java/org/nuiton/test/topia src/main/resources
by fdesbois@users.nuiton.org 21 Apr '10
by fdesbois@users.nuiton.org 21 Apr '10
21 Apr '10
Author: fdesbois
Date: 2010-04-21 18:06:34 +0200 (Wed, 21 Apr 2010)
New Revision: 407
Log:
Stop execution after 1 hour (not nbExecutions which is not efficient). Locks method is added but not used anymore -> error #546 in ToPIA resolve issue on ConcurrentModificationException.
Modified:
testTopiaPostgresError/trunk/pom.xml
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
testTopiaPostgresError/trunk/src/main/resources/log4j.properties
Modified: testTopiaPostgresError/trunk/pom.xml
===================================================================
--- testTopiaPostgresError/trunk/pom.xml 2010-04-21 09:27:50 UTC (rev 406)
+++ testTopiaPostgresError/trunk/pom.xml 2010-04-21 16:06:34 UTC (rev 407)
@@ -141,7 +141,7 @@
<!-- libraries version -->
<i18n.version>1.2.1</i18n.version>
<nuitonutils.version>1.2.2</nuitonutils.version>
- <topia.version>2.3.3-SNAPSHOT</topia.version>
+ <topia.version>2.4-SNAPSHOT</topia.version>
</properties>
<!-- ************************************************************* -->
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java 2010-04-21 09:27:50 UTC (rev 406)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java 2010-04-21 16:06:34 UTC (rev 407)
@@ -1,9 +1,10 @@
package org.nuiton.test.topia;
+import java.util.ConcurrentModificationException;
import java.util.TimerTask;
-import java.util.logging.Level;
import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,18 +32,21 @@
protected String name;
- protected int currentExecution;
+ protected int nbHours;
- public int nbExecutions;
+// protected int currentExecution;
+// public int nbExecutions;
+
protected static long globalStart = System.currentTimeMillis();
protected static final Object lock = new Object();
protected static Boolean token = false;
- public AbstractThread(int nbExecutions, String name) {
+ public AbstractThread(String name) {
this.name = name;
- this.nbExecutions = nbExecutions * 1000;
+ this.nbHours = 1;
+// this.nbExecutions = nbExecutions * 1000;
}
@Override
@@ -51,54 +55,40 @@
startTime = System.currentTimeMillis();
if (logger.isInfoEnabled()) {
- logger.info("Start " + name + " for " + nbExecutions +
- " executions after " +
+ logger.info("Start " + name + " for " + nbHours + " hour(s) after " +
DurationFormatUtils.formatDurationHMS(
startTime - globalStart));
}
- for (currentExecution = 0; currentExecution < nbExecutions;
- currentExecution ++) {
+ while(true) {
if (!manager.isStopped()) {
try {
- synchronized (lock) {
- // Do not stop waiting until token is free
- while (token) {
- if (logger.isDebugEnabled()) {
- logger.debug(name + " waiting...");
- }
- lock.wait();
- if (logger.isDebugEnabled()) {
- logger.debug(name + " no longer waiting");
- }
+ // Execute
+ String message = execute();
+
+ // Check message to display it and may stop execution
+ // depends on current time
+ if (message != null) {
+ long duration = System.currentTimeMillis() - startTime;
+ if (logger.isInfoEnabled()) {
+ logger.info(name + " : " + message + " after " +
+ DurationFormatUtils.formatDurationHMS(duration));
}
- // Take the token to lock other thread
- if (logger.isDebugEnabled()) {
- logger.debug(name + " take the token");
+
+ int hour = Integer.parseInt(
+ DurationFormatUtils.formatDuration(duration, "H"));
+
+ if (hour == nbHours) {
+ break;
}
- token = true;
}
- if (logger.isDebugEnabled()) {
- logger.debug(name + " execute...");
+
+ } catch (ConcurrentModificationException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Concurrent error", eee);
}
- // Execute
- execute();
- synchronized (lock) {
- if (logger.isDebugEnabled()) {
- logger.debug(name + " release the token");
- }
- // Release the token and notify other that the token
- // is free
- token = false;
- lock.notifyAll();
- }
- // Sleep to permit the unlocked Thread to have time to take
- // the token
- if (logger.isDebugEnabled()) {
- logger.debug(name + " go to sleep a while");
- }
- Thread.sleep(200);
-
+ // Will stop the application
+ manager.stopTest();
} catch (InterruptedException eee) {
if (logger.isErrorEnabled()) {
logger.error("Interrupted during sleep or wait", eee);
@@ -121,6 +111,47 @@
}
}
- protected abstract void execute()
+ public void lock() throws InterruptedException {
+ synchronized (lock) {
+ // Do not stop waiting until token is free
+ while (token) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " waiting...");
+ }
+ lock.wait();
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " no longer waiting");
+ }
+ }
+ // Take the token to lock other thread
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " take the token");
+ }
+ token = true;
+ }
+ }
+
+ public void unlock() throws InterruptedException {
+ synchronized (lock) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " release the token");
+ }
+ // Release the token and notify other that the token
+ // is free
+ token = false;
+ lock.notifyAll();
+ }
+ }
+
+ public void pause() throws InterruptedException {
+ // Pause the thread a while (not essential but avoid doing lots of
+ // actions in a few time)
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " go to sleep a while");
+ }
+ Thread.sleep(200);
+ }
+
+ protected abstract String execute()
throws TopiaException, InterruptedException;
}
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java 2010-04-21 09:27:50 UTC (rev 406)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java 2010-04-21 16:06:34 UTC (rev 407)
@@ -26,14 +26,14 @@
protected int tic;
public ReadThread() {
- // 15 executions during approximatively 1 hour
- super(15, ReadThread.class.getName());
+ super(ReadThread.class.getName());
}
@Override
- protected synchronized void execute()
+ protected synchronized String execute()
throws TopiaException, InterruptedException {
TopiaContext transaction = null;
+ String message = null;
try {
transaction = manager.getRootContext().beginTransaction();
@@ -48,19 +48,15 @@
tic++;
- if ((tic % 300 == 0) && logger.isInfoEnabled()) {
- long stopTime = System.currentTimeMillis();
- long time = stopTime - startTime;
-
- logger.info(versions.size() + " values read after " +
- DurationFormatUtils.formatDurationHMS(time) +
- " (exec " + currentExecution + ")");
+ if (tic % 300 == 0) {
+ message = versions.size() + " values read";
}
} finally {
if (transaction != null) {
transaction.closeContext();
}
}
+ return message;
}
}
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java 2010-04-21 09:27:50 UTC (rev 406)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java 2010-04-21 16:06:34 UTC (rev 407)
@@ -29,8 +29,7 @@
protected int tic;
public WriteThread() {
- // 15 executions during approximatively 1 hour
- super(15, WriteThread.class.getName());
+ super(WriteThread.class.getName());
}
/**
@@ -39,12 +38,14 @@
* The field version is used to save the increment global (total number
* of saved).
*
+ * @return message each 300 executions
* @throws TopiaException
* @throws InterruptedException
*/
@Override
- protected synchronized void execute()
+ protected synchronized String execute()
throws TopiaException, InterruptedException {
+ String message = null;
TopiaContext transaction = null;
try {
transaction = manager.getRootContext().beginTransaction();
@@ -76,6 +77,7 @@
dao.delete(exist);
increment++;
transaction.commitTransaction();
+ pause();
}
// UPDATE if alea is divided by 20
} else if (alea % 20 == 0) {
@@ -98,10 +100,10 @@
exist.setVersion(String.valueOf(increment));
increment++;
transaction.commitTransaction();
+ pause();
}
// CREATE if alea is divided by 10
} else if (alea % 10 == 0) {
-
TMSVersion create = dao.create(TMSVersion.VERSION,
String.valueOf(increment));
@@ -109,26 +111,26 @@
logger.debug("create the " + increment + " entry id = "
+ create.getTopiaId());
}
-
increment ++;
transaction.commitTransaction();
+ pause();
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("do nothing");
+ }
}
tic++;
- if ((tic % 300 == 0) && logger.isInfoEnabled()) {
- long stopTime = System.currentTimeMillis();
- long time = stopTime - startTime;
-
- logger.info(increment + " create/update or delete actions" +
- " after " + DurationFormatUtils.formatDurationHMS(time) +
- " (exec " + currentExecution + ")");
+ if (tic % 300 == 0) {
+ message = increment + " create/update or delete actions";
}
} finally {
if (transaction != null) {
transaction.closeContext();
}
}
+ return message;
}
}
Modified: testTopiaPostgresError/trunk/src/main/resources/log4j.properties
===================================================================
--- testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-21 09:27:50 UTC (rev 406)
+++ testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-21 16:06:34 UTC (rev 407)
@@ -13,4 +13,6 @@
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
-log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
\ No newline at end of file
+log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
+
+log4j.logger.org.nuiton.test.topia=DEBUG
\ No newline at end of file
1
0
r406 - in testTopiaPostgresError/trunk/src/main: java/org/nuiton/test/topia resources
by fdesbois@users.nuiton.org 21 Apr '10
by fdesbois@users.nuiton.org 21 Apr '10
21 Apr '10
Author: fdesbois
Date: 2010-04-21 11:27:50 +0200 (Wed, 21 Apr 2010)
New Revision: 406
Log:
Third version :
- no more ConcurrentException (token + lock)
- use Timer and change superclass of Thread to TimerTask to use periodically execution (each 3 hours)
- The execution takes approximatively 1 hour, so 2 hours of inactivity before restarting the thread
Modified:
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
testTopiaPostgresError/trunk/src/main/resources/log4j.properties
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java 2010-04-18 10:14:54 UTC (rev 405)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java 2010-04-21 09:27:50 UTC (rev 406)
@@ -1,6 +1,8 @@
package org.nuiton.test.topia;
+import java.util.TimerTask;
+import java.util.logging.Level;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.nuiton.topia.TopiaException;
import org.slf4j.Logger;
@@ -17,7 +19,7 @@
* Mise a jour: $Date$
* par : $Author$
*/
-public abstract class AbstractThread implements Runnable {
+public abstract class AbstractThread extends TimerTask {
private static final Logger logger =
LoggerFactory.getLogger(AbstractThread.class);
@@ -25,51 +27,92 @@
protected TestManager manager = TestManager.getInstance();
- protected volatile boolean stop;
-
protected long startTime;
-
- protected long startMilliseconds;
protected String name;
- public AbstractThread(long startMilliseconds, String name) {
- this.startMilliseconds = startMilliseconds;
+ protected int currentExecution;
+
+ public int nbExecutions;
+
+ protected static long globalStart = System.currentTimeMillis();
+
+ protected static final Object lock = new Object();
+ protected static Boolean token = false;
+
+ public AbstractThread(int nbExecutions, String name) {
this.name = name;
+ this.nbExecutions = nbExecutions * 1000;
}
- public synchronized void stop() {
- stop = true;
- }
-
@Override
public void run() {
+ startTime = System.currentTimeMillis();
+
if (logger.isInfoEnabled()) {
- logger.info("Start " + name + " in " + startMilliseconds + "ms");
+ logger.info("Start " + name + " for " + nbExecutions +
+ " executions after " +
+ DurationFormatUtils.formatDurationHMS(
+ startTime - globalStart));
}
- startTime = System.currentTimeMillis();
- try {
- Thread.sleep(startMilliseconds);
- } catch (InterruptedException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Thread interrupted during sleep", eee);
- }
- }
+ for (currentExecution = 0; currentExecution < nbExecutions;
+ currentExecution ++) {
+ if (!manager.isStopped()) {
+ try {
+ synchronized (lock) {
+ // Do not stop waiting until token is free
+ while (token) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " waiting...");
+ }
+ lock.wait();
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " no longer waiting");
+ }
+ }
+ // Take the token to lock other thread
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " take the token");
+ }
+ token = true;
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " execute...");
+ }
+ // Execute
+ execute();
+ synchronized (lock) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " release the token");
+ }
+ // Release the token and notify other that the token
+ // is free
+ token = false;
+ lock.notifyAll();
+ }
+ // Sleep to permit the unlocked Thread to have time to take
+ // the token
+ if (logger.isDebugEnabled()) {
+ logger.debug(name + " go to sleep a while");
+ }
+ Thread.sleep(200);
- while(!stop) {
- try {
- execute();
- } catch (TopiaException eee) {
- long stopTime = System.currentTimeMillis();
- if (logger.isErrorEnabled()) {
- logger.error("ERROR after " +
- DurationFormatUtils.formatDurationHMS(
- stopTime - startTime), eee);
+ } catch (InterruptedException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Interrupted during sleep or wait", eee);
+ }
+ } catch (TopiaException eee) {
+ long stopTime = System.currentTimeMillis();
+ if (logger.isErrorEnabled()) {
+ logger.error("ERROR after " +
+ DurationFormatUtils.formatDurationHMS(
+ stopTime - startTime), eee);
+ }
+ // Will stop the application
+ manager.stopTest();
}
- // Will stop the application
- manager.stopTest();
}
}
@@ -78,5 +121,6 @@
}
}
- protected abstract void execute() throws TopiaException;
+ protected abstract void execute()
+ throws TopiaException, InterruptedException;
}
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java 2010-04-18 10:14:54 UTC (rev 405)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java 2010-04-21 09:27:50 UTC (rev 406)
@@ -26,11 +26,13 @@
protected int tic;
public ReadThread() {
- super(1000, ReadThread.class.getName());
+ // 15 executions during approximatively 1 hour
+ super(15, ReadThread.class.getName());
}
@Override
- protected synchronized void execute() throws TopiaException {
+ protected synchronized void execute()
+ throws TopiaException, InterruptedException {
TopiaContext transaction = null;
try {
transaction = manager.getRootContext().beginTransaction();
@@ -44,22 +46,16 @@
logger.debug("Reading " + versions.size() + " entries");
}
- Thread.sleep(500);
-
tic++;
- if ((tic % 100 == 0) && logger.isInfoEnabled()) {
+ if ((tic % 300 == 0) && logger.isInfoEnabled()) {
long stopTime = System.currentTimeMillis();
long time = stopTime - startTime;
logger.info(versions.size() + " values read after " +
- DurationFormatUtils.formatDurationHMS(time));
+ DurationFormatUtils.formatDurationHMS(time) +
+ " (exec " + currentExecution + ")");
}
-
- } catch (InterruptedException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Thread interrupted during sleep", eee);
- }
} finally {
if (transaction != null) {
transaction.closeContext();
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java 2010-04-18 10:14:54 UTC (rev 405)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java 2010-04-21 09:27:50 UTC (rev 406)
@@ -3,15 +3,12 @@
import java.util.Locale;
import java.util.Properties;
-import java.util.logging.Level;
+import java.util.Timer;
import org.nuiton.i18n.I18n;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaContextFactory;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaNotFoundException;
-import org.nuiton.topia.migration.MigrationServiceDAOHelper;
-import org.nuiton.topia.migration.TMSVersion;
-import org.nuiton.topia.migration.TMSVersionDAO;
import org.nuiton.topia.migration.TMSVersionImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,8 +29,6 @@
private static final Logger logger =
LoggerFactory.getLogger(TestManager.class);
-// protected ApplicationConfig configuration;
-
protected static TestManager instance;
protected Properties configuration;
@@ -42,6 +37,16 @@
protected ReadThread readThread;
+ protected Timer readTimer;
+
+ protected Timer writeTimer;
+
+ private static final long THREE_HOURS_PERIOD = 10800000;
+
+ protected volatile boolean stop;
+
+ public static final Object waitForStop = new Object();
+
public static TestManager getInstance() {
if (instance == null) {
instance = new TestManager();
@@ -68,73 +73,44 @@
TMSVersionImpl.class.getName());
I18n.init(Locale.FRANCE);
-
- // Create first entry
-// TopiaContext transaction = null;
-// try {
-// if (logger.isInfoEnabled()) {
-// logger.info("Open first transaction to create main entry");
-// }
-// transaction = TopiaContextFactory.getContext(configuration).
-// beginTransaction();
-// TMSVersionDAO dao =
-// MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
-//
-// TMSVersion entry = dao.create(TMSVersion.VERSION, "1");
-//
-// mainTopiaId = entry.getTopiaId();
-// if (logger.isInfoEnabled()) {
-// logger.info("Save the entry with id = " + mainTopiaId);
-// }
-// transaction.commitTransaction();
-//
-// } catch (TopiaException eee) {
-// if (logger.isErrorEnabled()) {
-// logger.error("Error when create the first entry : ", eee);
-// }
-// } finally {
-// if (transaction != null) {
-// try {
-// transaction.closeContext();
-// } catch (TopiaException eee) {
-// if (logger.isErrorEnabled()) {
-// logger.error("Error on closeContext : ", eee);
-// }
-// }
-// }
-// }
}
public TopiaContext getRootContext() throws TopiaNotFoundException {
return TopiaContextFactory.getContext(configuration);
}
+ public boolean isStopped() {
+ return stop;
+ }
+
public void startTest() {
- if (writeThread == null) {
- writeThread = new WriteThread();
- new Thread(writeThread).start();
+ // Execution of thread during 1 hour + 2 hours of inactivity
+ if (readTimer == null) {
+ readTimer = new Timer();
+ readTimer.schedule(new ReadThread(), 1000, THREE_HOURS_PERIOD);
}
- if (readThread == null) {
- readThread = new ReadThread();
- new Thread(readThread).start();
+ if (writeTimer == null) {
+ writeTimer = new Timer();
+ writeTimer.schedule(new WriteThread(), 0, THREE_HOURS_PERIOD);
}
}
public void stopTest() {
- if (writeThread != null) {
- writeThread.stop();
- writeThread = null;
- }
- if (readThread != null) {
- readThread.stop();
- readThread = null;
- }
- try {
- getRootContext().closeContext();
- } catch (TopiaException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Error on close root context : ", eee);
+ if (!stop) {
+ stop = true;
+ if (readTimer != null) {
+ readTimer.cancel();
}
+ if (writeTimer != null) {
+ writeTimer.cancel();
+ }
+ try {
+ getRootContext().closeContext();
+ } catch (TopiaException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error on close root context : ", eee);
+ }
+ }
}
}
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java 2010-04-18 10:14:54 UTC (rev 405)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java 2010-04-21 09:27:50 UTC (rev 406)
@@ -29,7 +29,8 @@
protected int tic;
public WriteThread() {
- super(0, WriteThread.class.getName());
+ // 15 executions during approximatively 1 hour
+ super(15, WriteThread.class.getName());
}
/**
@@ -39,9 +40,11 @@
* of saved).
*
* @throws TopiaException
+ * @throws InterruptedException
*/
@Override
- protected synchronized void execute() throws TopiaException {
+ protected synchronized void execute()
+ throws TopiaException, InterruptedException {
TopiaContext transaction = null;
try {
transaction = manager.getRootContext().beginTransaction();
@@ -53,8 +56,6 @@
// Create an alea between 0 and 1000
int alea = (int)(random.nextFloat() * 1000);
- boolean actionDone = false;
-
// DELETE if alea is divided by 100
if (alea % 100 == 0) {
// Alea number over number of existing entries
@@ -75,7 +76,6 @@
dao.delete(exist);
increment++;
transaction.commitTransaction();
- actionDone = true;
}
// UPDATE if alea is divided by 20
} else if (alea % 20 == 0) {
@@ -98,7 +98,6 @@
exist.setVersion(String.valueOf(increment));
increment++;
transaction.commitTransaction();
- actionDone = true;
}
// CREATE if alea is divided by 10
} else if (alea % 10 == 0) {
@@ -113,24 +112,18 @@
increment ++;
transaction.commitTransaction();
- actionDone = true;
}
- Thread.sleep(100);
-
tic++;
- if ((tic % 600 == 0) && logger.isInfoEnabled()) {
+ if ((tic % 300 == 0) && logger.isInfoEnabled()) {
long stopTime = System.currentTimeMillis();
long time = stopTime - startTime;
logger.info(increment + " create/update or delete actions" +
- " after " + DurationFormatUtils.formatDurationHMS(time));
+ " after " + DurationFormatUtils.formatDurationHMS(time) +
+ " (exec " + currentExecution + ")");
}
- } catch (InterruptedException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Thread interrupted during sleep", eee);
- }
} finally {
if (transaction != null) {
transaction.closeContext();
Modified: testTopiaPostgresError/trunk/src/main/resources/log4j.properties
===================================================================
--- testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-18 10:14:54 UTC (rev 405)
+++ testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-21 09:27:50 UTC (rev 406)
@@ -13,7 +13,4 @@
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
-log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
-
-log4j.logger.org.nuiton.test.topia=DEBUG
-log4j.logger.org.nuiton.topia=INFO
\ No newline at end of file
+log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
\ No newline at end of file
1
0
r405 - in testTopiaPostgresError/trunk: . src/main/java/org/nuiton/test/topia src/main/resources
by fdesbois@users.nuiton.org 18 Apr '10
by fdesbois@users.nuiton.org 18 Apr '10
18 Apr '10
Author: fdesbois
Date: 2010-04-18 12:14:54 +0200 (Sun, 18 Apr 2010)
New Revision: 405
Log:
2nd version : two thread one read and one write.
Added:
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
Removed:
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java
Modified:
testTopiaPostgresError/trunk/README.txt
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java
testTopiaPostgresError/trunk/src/main/resources/log4j.properties
Modified: testTopiaPostgresError/trunk/README.txt
===================================================================
--- testTopiaPostgresError/trunk/README.txt 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/README.txt 2010-04-18 10:14:54 UTC (rev 405)
@@ -0,0 +1,8 @@
+To run the test :
+mvn clean install tomcat:run -Dtopiatest.home=/home/fdesbois/.local/topiatest
+
+Then open a browser to start the appli :
+http://localhost:8080/test-topia-postgres-error/start
+
+To stop the appli :
+http://localhost:8080/test-topia-postgres-error/stop
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -0,0 +1,82 @@
+
+package org.nuiton.test.topia;
+
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.topia.TopiaException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * AbstractThread
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public abstract class AbstractThread implements Runnable {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(AbstractThread.class);
+
+
+ protected TestManager manager = TestManager.getInstance();
+
+ protected volatile boolean stop;
+
+ protected long startTime;
+
+ protected long startMilliseconds;
+
+ protected String name;
+
+ public AbstractThread(long startMilliseconds, String name) {
+ this.startMilliseconds = startMilliseconds;
+ this.name = name;
+ }
+
+ public synchronized void stop() {
+ stop = true;
+ }
+
+ @Override
+ public void run() {
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Start " + name + " in " + startMilliseconds + "ms");
+ }
+
+ startTime = System.currentTimeMillis();
+ try {
+ Thread.sleep(startMilliseconds);
+ } catch (InterruptedException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Thread interrupted during sleep", eee);
+ }
+ }
+
+ while(!stop) {
+ try {
+ execute();
+ } catch (TopiaException eee) {
+ long stopTime = System.currentTimeMillis();
+ if (logger.isErrorEnabled()) {
+ logger.error("ERROR after " +
+ DurationFormatUtils.formatDurationHMS(
+ stopTime - startTime), eee);
+ }
+ // Will stop the application
+ manager.stopTest();
+ }
+ }
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Stop " + name);
+ }
+ }
+
+ protected abstract void execute() throws TopiaException;
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/AbstractThread.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -0,0 +1,70 @@
+
+package org.nuiton.test.topia;
+
+import java.util.List;
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.migration.MigrationServiceDAOHelper;
+import org.nuiton.topia.migration.TMSVersion;
+import org.nuiton.topia.migration.TMSVersionDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ThreadTest
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ */
+public class ReadThread extends AbstractThread {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(ReadThread.class);
+
+ protected int tic;
+
+ public ReadThread() {
+ super(1000, ReadThread.class.getName());
+ }
+
+ @Override
+ protected synchronized void execute() throws TopiaException {
+ TopiaContext transaction = null;
+ try {
+ transaction = manager.getRootContext().beginTransaction();
+
+ TMSVersionDAO dao =
+ MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
+
+ List<TMSVersion> versions = dao.findAll();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Reading " + versions.size() + " entries");
+ }
+
+ Thread.sleep(500);
+
+ tic++;
+
+ if ((tic % 100 == 0) && logger.isInfoEnabled()) {
+ long stopTime = System.currentTimeMillis();
+ long time = stopTime - startTime;
+
+ logger.info(versions.size() + " values read after " +
+ DurationFormatUtils.formatDurationHMS(time));
+ }
+
+ } catch (InterruptedException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Thread interrupted during sleep", eee);
+ }
+ } finally {
+ if (transaction != null) {
+ transaction.closeContext();
+ }
+ }
+ }
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ReadThread.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -50,7 +50,7 @@
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- TopiaManager.getInstance().startTest();
+ TestManager.getInstance().startTest();
}
/**
Modified: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -32,7 +32,7 @@
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- TopiaManager.getInstance().stopTest();
+ TestManager.getInstance().stopTest();
}
/**
Copied: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java (from rev 404, testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java)
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -0,0 +1,141 @@
+
+package org.nuiton.test.topia;
+
+import java.util.Locale;
+import java.util.Properties;
+import java.util.logging.Level;
+import org.nuiton.i18n.I18n;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topia.migration.MigrationServiceDAOHelper;
+import org.nuiton.topia.migration.TMSVersion;
+import org.nuiton.topia.migration.TMSVersionDAO;
+import org.nuiton.topia.migration.TMSVersionImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TopiaManager
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class TestManager {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(TestManager.class);
+
+// protected ApplicationConfig configuration;
+
+ protected static TestManager instance;
+
+ protected Properties configuration;
+
+ protected WriteThread writeThread;
+
+ protected ReadThread readThread;
+
+ public static TestManager getInstance() {
+ if (instance == null) {
+ instance = new TestManager();
+ }
+ return instance;
+ }
+
+ private TestManager() {
+ configuration = new Properties();
+ // Config for Postgres
+ configuration.put("hibernate.hbm2ddl.auto", "create");
+ configuration.put("hibernate.show_sql", "false");
+ configuration.put("hibernate.dialect",
+ "org.hibernate.dialect.PostgreSQLDialect");
+ configuration.put("hibernate.connection.username","topia");
+ configuration.put("hibernate.connection.password","");
+ configuration.put("hibernate.connection.driver_class",
+ "org.postgresql.Driver");
+ configuration.put("hibernate.connection.url",
+ "jdbc:postgresql:topiatest");
+
+ // Config for Topia service Migration
+ configuration.put("topia.persistence.classes",
+ TMSVersionImpl.class.getName());
+
+ I18n.init(Locale.FRANCE);
+
+ // Create first entry
+// TopiaContext transaction = null;
+// try {
+// if (logger.isInfoEnabled()) {
+// logger.info("Open first transaction to create main entry");
+// }
+// transaction = TopiaContextFactory.getContext(configuration).
+// beginTransaction();
+// TMSVersionDAO dao =
+// MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
+//
+// TMSVersion entry = dao.create(TMSVersion.VERSION, "1");
+//
+// mainTopiaId = entry.getTopiaId();
+// if (logger.isInfoEnabled()) {
+// logger.info("Save the entry with id = " + mainTopiaId);
+// }
+// transaction.commitTransaction();
+//
+// } catch (TopiaException eee) {
+// if (logger.isErrorEnabled()) {
+// logger.error("Error when create the first entry : ", eee);
+// }
+// } finally {
+// if (transaction != null) {
+// try {
+// transaction.closeContext();
+// } catch (TopiaException eee) {
+// if (logger.isErrorEnabled()) {
+// logger.error("Error on closeContext : ", eee);
+// }
+// }
+// }
+// }
+ }
+
+ public TopiaContext getRootContext() throws TopiaNotFoundException {
+ return TopiaContextFactory.getContext(configuration);
+ }
+
+ public void startTest() {
+ if (writeThread == null) {
+ writeThread = new WriteThread();
+ new Thread(writeThread).start();
+ }
+ if (readThread == null) {
+ readThread = new ReadThread();
+ new Thread(readThread).start();
+ }
+ }
+
+ public void stopTest() {
+ if (writeThread != null) {
+ writeThread.stop();
+ writeThread = null;
+ }
+ if (readThread != null) {
+ readThread.stop();
+ readThread = null;
+ }
+ try {
+ getRootContext().closeContext();
+ } catch (TopiaException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error on close root context : ", eee);
+ }
+ }
+ }
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TestManager.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: svn:mergeinfo
+
Deleted: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -1,96 +0,0 @@
-
-package org.nuiton.test.topia;
-
-import org.apache.commons.lang.time.DurationFormatUtils;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.migration.MigrationServiceDAOHelper;
-import org.nuiton.topia.migration.TMSVersion;
-import org.nuiton.topia.migration.TMSVersionDAO;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * ThreadTest
- *
- * Created: 16 avr. 2010
- *
- * @author fdesbois
- */
-public class ThreadTest implements Runnable {
-
- private static final Logger logger =
- LoggerFactory.getLogger(ThreadTest.class);
-
- protected TopiaManager manager = TopiaManager.getInstance();
-
- protected volatile boolean stop;
-
- protected long startTime;
-
- public synchronized void stop() {
- stop = true;
- }
-
- @Override
- public void run() {
-
- if (logger.isInfoEnabled()) {
- logger.info("Start Thread");
- }
-
- startTime = System.currentTimeMillis();
-
- while(!stop) {
- try {
- execute();
- } catch (TopiaException eee) {
- long stopTime = System.currentTimeMillis();
- if (logger.isErrorEnabled()) {
- logger.error("ERROR after " +
- DurationFormatUtils.formatDurationHMS(
- stopTime - startTime), eee);
- }
- manager.stopTest();
- }
- }
-
- if (logger.isInfoEnabled()) {
- logger.info("Stop Thread");
- }
- }
-
- protected synchronized void execute() throws TopiaException {
- TopiaContext transaction = null;
- try {
- transaction = manager.getRootContext().beginTransaction();
-
- TMSVersionDAO dao =
- MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
-
- TMSVersion version = dao.findByTopiaId(manager.getMainTopiaId());
-
- Thread.sleep(100);
-
- int value = Integer.parseInt(version.getVersion());
- version.setVersion(String.valueOf(value + 1));
-
- if ((value % 500 == 0) && logger.isInfoEnabled()) {
- long stopTime = System.currentTimeMillis();
- logger.info("Value is " + version.getVersion() + " after " +
- DurationFormatUtils.formatDurationHMS(stopTime - startTime));
- }
-
- transaction.commitTransaction();
- } catch (InterruptedException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Thread interrupted during sleep", eee);
- }
- } finally {
- if (transaction != null) {
- transaction.closeContext();
- }
- }
- }
-
-}
Deleted: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -1,136 +0,0 @@
-
-package org.nuiton.test.topia;
-
-import java.util.Locale;
-import java.util.Properties;
-import java.util.logging.Level;
-import org.nuiton.i18n.I18n;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaContextFactory;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaNotFoundException;
-import org.nuiton.topia.migration.MigrationServiceDAOHelper;
-import org.nuiton.topia.migration.TMSVersion;
-import org.nuiton.topia.migration.TMSVersionDAO;
-import org.nuiton.topia.migration.TMSVersionImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * TopiaManager
- *
- * Created: 16 avr. 2010
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class TopiaManager {
-
- private static final Logger logger =
- LoggerFactory.getLogger(TopiaManager.class);
-
-// protected ApplicationConfig configuration;
-
- protected static TopiaManager instance;
-
- protected Properties configuration;
-
- protected String mainTopiaId;
-
- protected ThreadTest thread;
-
- public static TopiaManager getInstance() {
- if (instance == null) {
- instance = new TopiaManager();
- }
- return instance;
- }
-
- private TopiaManager() {
- configuration = new Properties();
- // Config for Postgres
- configuration.put("hibernate.hbm2ddl.auto", "create");
- configuration.put("hibernate.show_sql", "false");
- configuration.put("hibernate.dialect",
- "org.hibernate.dialect.PostgreSQLDialect");
- configuration.put("hibernate.connection.username","topia");
- configuration.put("hibernate.connection.password","");
- configuration.put("hibernate.connection.driver_class",
- "org.postgresql.Driver");
- configuration.put("hibernate.connection.url",
- "jdbc:postgresql:topiatest");
-
- // Config for Topia service Migration
- configuration.put("topia.persistence.classes",
- TMSVersionImpl.class.getName());
-
- I18n.init(Locale.FRANCE);
-
- // Create first entry
- TopiaContext transaction = null;
- try {
- if (logger.isInfoEnabled()) {
- logger.info("Open first transaction to create main entry");
- }
- transaction = TopiaContextFactory.getContext(configuration).
- beginTransaction();
- TMSVersionDAO dao =
- MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
-
- TMSVersion entry = dao.create(TMSVersion.VERSION, "1");
-
- mainTopiaId = entry.getTopiaId();
- if (logger.isInfoEnabled()) {
- logger.info("Save the entry with id = " + mainTopiaId);
- }
- transaction.commitTransaction();
-
- } catch (TopiaException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Error when create the first entry : ", eee);
- }
- } finally {
- if (transaction != null) {
- try {
- transaction.closeContext();
- } catch (TopiaException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Error on closeContext : ", eee);
- }
- }
- }
- }
- }
-
- public TopiaContext getRootContext() throws TopiaNotFoundException {
- return TopiaContextFactory.getContext(configuration);
- }
-
- public String getMainTopiaId() {
- return mainTopiaId;
- }
-
- public void startTest() {
- if (thread == null) {
- thread = new ThreadTest();
- new Thread(thread).start();
- }
- }
-
- public void stopTest() {
- if (thread != null) {
- thread.stop();
- try {
- getRootContext().closeContext();
- } catch (TopiaException eee) {
- if (logger.isErrorEnabled()) {
- logger.error("Error on close root context : ", eee);
- }
- }
- }
- }
-
-}
Copied: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java (from rev 404, testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java)
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java 2010-04-18 10:14:54 UTC (rev 405)
@@ -0,0 +1,141 @@
+
+package org.nuiton.test.topia;
+
+import java.util.Random;
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.migration.MigrationServiceDAOHelper;
+import org.nuiton.topia.migration.TMSVersion;
+import org.nuiton.topia.migration.TMSVersionDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ThreadTest
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ */
+public class WriteThread extends AbstractThread {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(WriteThread.class);
+
+ protected int increment;
+
+ protected int tic;
+
+ public WriteThread() {
+ super(0, WriteThread.class.getName());
+ }
+
+ /**
+ * Create an entry at random over 10, update an existing one over 20
+ * and delete one over 100.
+ * The field version is used to save the increment global (total number
+ * of saved).
+ *
+ * @throws TopiaException
+ */
+ @Override
+ protected synchronized void execute() throws TopiaException {
+ TopiaContext transaction = null;
+ try {
+ transaction = manager.getRootContext().beginTransaction();
+
+ TMSVersionDAO dao =
+ MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
+
+ Random random = new Random();
+ // Create an alea between 0 and 1000
+ int alea = (int)(random.nextFloat() * 1000);
+
+ boolean actionDone = false;
+
+ // DELETE if alea is divided by 100
+ if (alea % 100 == 0) {
+ // Alea number over number of existing entries
+ int alea2 = (int)(random.nextFloat() * dao.size());
+
+ // Only one row will be return
+ TopiaQuery query = dao.createQuery().setLimit(alea2, alea2 + 1);
+ TMSVersion exist = dao.findByQuery(query);
+
+ if (exist == null && logger.isWarnEnabled()) {
+ logger.warn("the entry doesn't exist in position " +
+ alea2 + " ?!?");
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("delete the " + increment + " entry id = "
+ + exist.getTopiaId());
+ }
+ dao.delete(exist);
+ increment++;
+ transaction.commitTransaction();
+ actionDone = true;
+ }
+ // UPDATE if alea is divided by 20
+ } else if (alea % 20 == 0) {
+
+ // Alea number over number of existing entries
+ int alea2 = (int)(random.nextFloat() * dao.size());
+
+ // Only one row will be return
+ TopiaQuery query = dao.createQuery().setLimit(alea2, alea2 + 1);
+ TMSVersion exist = dao.findByQuery(query);
+
+ if (exist == null && logger.isWarnEnabled()) {
+ logger.warn("the entry doesn't exist in position " +
+ alea2 + " ?!?");
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("update the " + increment + " entry id = "
+ + exist.getTopiaId());
+ }
+ exist.setVersion(String.valueOf(increment));
+ increment++;
+ transaction.commitTransaction();
+ actionDone = true;
+ }
+ // CREATE if alea is divided by 10
+ } else if (alea % 10 == 0) {
+
+ TMSVersion create = dao.create(TMSVersion.VERSION,
+ String.valueOf(increment));
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("create the " + increment + " entry id = "
+ + create.getTopiaId());
+ }
+
+ increment ++;
+ transaction.commitTransaction();
+ actionDone = true;
+ }
+
+ Thread.sleep(100);
+
+ tic++;
+
+ if ((tic % 600 == 0) && logger.isInfoEnabled()) {
+ long stopTime = System.currentTimeMillis();
+ long time = stopTime - startTime;
+
+ logger.info(increment + " create/update or delete actions" +
+ " after " + DurationFormatUtils.formatDurationHMS(time));
+ }
+ } catch (InterruptedException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Thread interrupted during sleep", eee);
+ }
+ } finally {
+ if (transaction != null) {
+ transaction.closeContext();
+ }
+ }
+ }
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/WriteThread.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: svn:mergeinfo
+
Modified: testTopiaPostgresError/trunk/src/main/resources/log4j.properties
===================================================================
--- testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-16 18:57:32 UTC (rev 404)
+++ testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-18 10:14:54 UTC (rev 405)
@@ -1,12 +1,17 @@
# Global logging configuration
-log4j.rootLogger=INFO, stdout, file
+log4j.rootLogger=DEBUG, stdout, file
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%c:%L) %M - %m%n
-log4j.appender.file=org.apache.log4j.FileAppender
-log4j.appender.file.file=${topiatest.log.home}/topiatest.log
+log4j.appender.file=org.apache.log4j.RollingFileAppender
+log4j.appender.file.file=${topiatest.home}/topiatest.log
+log4j.appender.file.MaxFileSize=10MB
+log4j.appender.file.Append=true
+log4j.appender.file.Threshold=DEBUG
+log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
1
0
Author: fdesbois
Date: 2010-04-16 20:57:32 +0200 (Fri, 16 Apr 2010)
New Revision: 404
Log:
Create project for testing error on Topia and Postgres (Socket closed)
Added:
testTopiaPostgresError/
testTopiaPostgresError/trunk/
testTopiaPostgresError/trunk/LICENSE.txt
testTopiaPostgresError/trunk/README.txt
testTopiaPostgresError/trunk/changelog.txt
testTopiaPostgresError/trunk/pom.xml
testTopiaPostgresError/trunk/src/
testTopiaPostgresError/trunk/src/main/
testTopiaPostgresError/trunk/src/main/java/
testTopiaPostgresError/trunk/src/main/java/org/
testTopiaPostgresError/trunk/src/main/java/org/nuiton/
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java
testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java
testTopiaPostgresError/trunk/src/main/resources/
testTopiaPostgresError/trunk/src/main/resources/log4j.properties
testTopiaPostgresError/trunk/src/main/webapp/
testTopiaPostgresError/trunk/src/main/webapp/META-INF/
testTopiaPostgresError/trunk/src/main/webapp/META-INF/context.xml
testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/
testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/web.xml
Property changes on: testTopiaPostgresError/trunk
___________________________________________________________________
Added: svn:ignore
+ target
nbactions.xml
Property changes on: testTopiaPostgresError/trunk/LICENSE.txt
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Property changes on: testTopiaPostgresError/trunk/README.txt
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Property changes on: testTopiaPostgresError/trunk/changelog.txt
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/pom.xml
===================================================================
--- testTopiaPostgresError/trunk/pom.xml (rev 0)
+++ testTopiaPostgresError/trunk/pom.xml 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,217 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
+ <parent>
+ <groupId>org.nuiton</groupId>
+ <artifactId>mavenpom4redmine</artifactId>
+ <version>2.1</version>
+ </parent>
+
+ <groupId>org.nuiton</groupId>
+ <artifactId>test-topia-postgres-error</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+
+ <dependencies>
+
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.5</version>
+ </dependency>
+<!-- <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.8.2</version>
+ </dependency>-->
+ <dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ <version>${nuitonutils.version}</version>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <!-- ToPIA -->
+ <dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>${topia.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-service-migration</artifactId>
+ <version>${topia.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.10</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.10</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>8.4-701.jdbc4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>TEST Topia Postgres Error</name>
+ <description>Test to find the error with application using ToPIA and
+ Postgres (Socket closed after a long time execution).</description>
+ <inceptionYear>2010</inceptionYear>
+
+ <organization>
+ <name>Code Lutin</name>
+ <url>http://www.codelutin.com/</url>
+ </organization>
+
+ <!-- Developpers, contributors... -->
+ <developers>
+ <developer>
+ <id>fdesbois</id>
+ <name>Florian Desbois</name>
+ <email>fdesbois(a)codelutin.com</email>
+ <organization>CodeLutin</organization>
+ <organizationUrl>http://www.codelutin.com</organizationUrl>
+ <timezone>+1</timezone>
+ <roles>
+ <role>Chef de Projet</role>
+ <role>Analyste</role>
+ <role>Développeur</role>
+ </roles>
+ </developer>
+ <!--<developer>
+ <name>Tony Chemit</name>
+ <id>tchemit</id>
+ <email>chemit(a)codelutin.com</email>
+ <organization>CodeLutin</organization>
+ <organizationUrl>http://www.codelutin.com</organizationUrl>
+ <timezone>+2</timezone>
+ <roles>
+ <role>Développeur</role>
+ </roles>
+ </developer>-->
+ </developers>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <packaging>war</packaging>
+
+ <properties>
+ <!-- libraries version -->
+ <i18n.version>1.2.1</i18n.version>
+ <nuitonutils.version>1.2.2</nuitonutils.version>
+ <topia.version>2.3.3-SNAPSHOT</topia.version>
+ </properties>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+
+ <!-- Source control management. -->
+ <scm>
+ <connection>scm:svn:http://svn.nuiton.org/svn/sandbox/testTopiaPostgresError/trunk</connection>
+ <developerConnection>scm:svn:http://svn.nuiton.org/svn/sandbox/testTopiaPostgresError/trunk</developerConnection>
+ <url>http://www.nuiton.org/repositories/browse/sandbox/testTopiaPostgresError/tr…</url>
+ </scm>
+
+ <build>
+<!-- <resources>
+ <resource>
+ <directory>src/main/filters</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>-->
+
+ <plugins>
+
+ <!-- plugin site -->
+<!-- <plugin>
+ <artifactId>maven-site-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.nuiton.jrst</groupId>
+ <artifactId>doxia-module-jrst</artifactId>
+ <version>${jrst.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>-->
+
+ <!--<plugin>
+ <groupId>org.nuiton.eugene</groupId>
+ <artifactId>maven-eugene-plugin</artifactId>
+ <version>${eugene.version}</version>
+ <configuration>
+ <inputs>zargo</inputs>
+ <resolver>org.nuiton.util.FasterCachedResourceResolver</resolver>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.nuiton.topia</groupId>
+ <artifactId>topia-persistence</artifactId>
+ <version>${topia.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>-->
+
+ <plugin>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>maven-i18n-plugin</artifactId>
+ <version>${i18n.version}</version>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+ <!-- No generation of reports for maven-site (will be generated for release) -->
+ <reporting>
+ <excludeDefaults>true</excludeDefaults>
+ </reporting>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+
+
+</project>
Property changes on: testTopiaPostgresError/trunk/pom.xml
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,78 @@
+/**
+ * *##% ChoReg
+ * Copyright (C) 2009 CodeLutin
+ *
+ * This program 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.
+ *
+ * This program 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>. ##%*
+ */
+
+package org.nuiton.test.topia;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * ViewServices.java
+ *
+ * Created on 2009-07-24
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author: fdesbois $
+ */
+public class StartTest extends HttpServlet {
+
+ // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
+ /**
+ * Handles the HTTP <code>GET</code> method.
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ TopiaManager.getInstance().startTest();
+ }
+
+ /**
+ * Handles the HTTP <code>POST</code> method.
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// </editor-fold>
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StartTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,60 @@
+
+package org.nuiton.test.topia;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * StopTest
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class StopTest extends HttpServlet {
+
+ // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
+ /**
+ * Handles the HTTP <code>GET</code> method.
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ TopiaManager.getInstance().stopTest();
+ }
+
+ /**
+ * Handles the HTTP <code>POST</code> method.
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// </editor-fold>
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/StopTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,96 @@
+
+package org.nuiton.test.topia;
+
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.migration.MigrationServiceDAOHelper;
+import org.nuiton.topia.migration.TMSVersion;
+import org.nuiton.topia.migration.TMSVersionDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ThreadTest
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ */
+public class ThreadTest implements Runnable {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(ThreadTest.class);
+
+ protected TopiaManager manager = TopiaManager.getInstance();
+
+ protected volatile boolean stop;
+
+ protected long startTime;
+
+ public synchronized void stop() {
+ stop = true;
+ }
+
+ @Override
+ public void run() {
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Start Thread");
+ }
+
+ startTime = System.currentTimeMillis();
+
+ while(!stop) {
+ try {
+ execute();
+ } catch (TopiaException eee) {
+ long stopTime = System.currentTimeMillis();
+ if (logger.isErrorEnabled()) {
+ logger.error("ERROR after " +
+ DurationFormatUtils.formatDurationHMS(
+ stopTime - startTime), eee);
+ }
+ manager.stopTest();
+ }
+ }
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Stop Thread");
+ }
+ }
+
+ protected synchronized void execute() throws TopiaException {
+ TopiaContext transaction = null;
+ try {
+ transaction = manager.getRootContext().beginTransaction();
+
+ TMSVersionDAO dao =
+ MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
+
+ TMSVersion version = dao.findByTopiaId(manager.getMainTopiaId());
+
+ Thread.sleep(100);
+
+ int value = Integer.parseInt(version.getVersion());
+ version.setVersion(String.valueOf(value + 1));
+
+ if ((value % 500 == 0) && logger.isInfoEnabled()) {
+ long stopTime = System.currentTimeMillis();
+ logger.info("Value is " + version.getVersion() + " after " +
+ DurationFormatUtils.formatDurationHMS(stopTime - startTime));
+ }
+
+ transaction.commitTransaction();
+ } catch (InterruptedException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Thread interrupted during sleep", eee);
+ }
+ } finally {
+ if (transaction != null) {
+ transaction.closeContext();
+ }
+ }
+ }
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/ThreadTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java
===================================================================
--- testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java (rev 0)
+++ testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,136 @@
+
+package org.nuiton.test.topia;
+
+import java.util.Locale;
+import java.util.Properties;
+import java.util.logging.Level;
+import org.nuiton.i18n.I18n;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaContextFactory;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaNotFoundException;
+import org.nuiton.topia.migration.MigrationServiceDAOHelper;
+import org.nuiton.topia.migration.TMSVersion;
+import org.nuiton.topia.migration.TMSVersionDAO;
+import org.nuiton.topia.migration.TMSVersionImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TopiaManager
+ *
+ * Created: 16 avr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class TopiaManager {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(TopiaManager.class);
+
+// protected ApplicationConfig configuration;
+
+ protected static TopiaManager instance;
+
+ protected Properties configuration;
+
+ protected String mainTopiaId;
+
+ protected ThreadTest thread;
+
+ public static TopiaManager getInstance() {
+ if (instance == null) {
+ instance = new TopiaManager();
+ }
+ return instance;
+ }
+
+ private TopiaManager() {
+ configuration = new Properties();
+ // Config for Postgres
+ configuration.put("hibernate.hbm2ddl.auto", "create");
+ configuration.put("hibernate.show_sql", "false");
+ configuration.put("hibernate.dialect",
+ "org.hibernate.dialect.PostgreSQLDialect");
+ configuration.put("hibernate.connection.username","topia");
+ configuration.put("hibernate.connection.password","");
+ configuration.put("hibernate.connection.driver_class",
+ "org.postgresql.Driver");
+ configuration.put("hibernate.connection.url",
+ "jdbc:postgresql:topiatest");
+
+ // Config for Topia service Migration
+ configuration.put("topia.persistence.classes",
+ TMSVersionImpl.class.getName());
+
+ I18n.init(Locale.FRANCE);
+
+ // Create first entry
+ TopiaContext transaction = null;
+ try {
+ if (logger.isInfoEnabled()) {
+ logger.info("Open first transaction to create main entry");
+ }
+ transaction = TopiaContextFactory.getContext(configuration).
+ beginTransaction();
+ TMSVersionDAO dao =
+ MigrationServiceDAOHelper.getTMSVersionDAO(transaction);
+
+ TMSVersion entry = dao.create(TMSVersion.VERSION, "1");
+
+ mainTopiaId = entry.getTopiaId();
+ if (logger.isInfoEnabled()) {
+ logger.info("Save the entry with id = " + mainTopiaId);
+ }
+ transaction.commitTransaction();
+
+ } catch (TopiaException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error when create the first entry : ", eee);
+ }
+ } finally {
+ if (transaction != null) {
+ try {
+ transaction.closeContext();
+ } catch (TopiaException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error on closeContext : ", eee);
+ }
+ }
+ }
+ }
+ }
+
+ public TopiaContext getRootContext() throws TopiaNotFoundException {
+ return TopiaContextFactory.getContext(configuration);
+ }
+
+ public String getMainTopiaId() {
+ return mainTopiaId;
+ }
+
+ public void startTest() {
+ if (thread == null) {
+ thread = new ThreadTest();
+ new Thread(thread).start();
+ }
+ }
+
+ public void stopTest() {
+ if (thread != null) {
+ thread.stop();
+ try {
+ getRootContext().closeContext();
+ } catch (TopiaException eee) {
+ if (logger.isErrorEnabled()) {
+ logger.error("Error on close root context : ", eee);
+ }
+ }
+ }
+ }
+
+}
Property changes on: testTopiaPostgresError/trunk/src/main/java/org/nuiton/test/topia/TopiaManager.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/resources/log4j.properties
===================================================================
--- testTopiaPostgresError/trunk/src/main/resources/log4j.properties (rev 0)
+++ testTopiaPostgresError/trunk/src/main/resources/log4j.properties 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,14 @@
+# Global logging configuration
+log4j.rootLogger=INFO, stdout, file
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%c:%L) %M - %m%n
+
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.file=${topiatest.log.home}/topiatest.log
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p [%t] (%c:%L) %M - %m%n
+
+log4j.logger.org.nuiton.test.topia=DEBUG
+log4j.logger.org.nuiton.topia=INFO
\ No newline at end of file
Property changes on: testTopiaPostgresError/trunk/src/main/resources/log4j.properties
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/webapp/META-INF/context.xml
===================================================================
--- testTopiaPostgresError/trunk/src/main/webapp/META-INF/context.xml (rev 0)
+++ testTopiaPostgresError/trunk/src/main/webapp/META-INF/context.xml 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Context antiJARLocking="true" path="/test-topia-postgres-error"/>
Property changes on: testTopiaPostgresError/trunk/src/main/webapp/META-INF/context.xml
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/web.xml
===================================================================
--- testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/web.xml (rev 0)
+++ testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/web.xml 2010-04-16 18:57:32 UTC (rev 404)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+ <display-name>Test Topia Postgres Error</display-name>
+ <servlet>
+ <servlet-name>StartTest</servlet-name>
+ <servlet-class>org.nuiton.test.topia.StartTest</servlet-class>
+ </servlet>
+ <servlet>
+ <servlet-name>StopTest</servlet-name>
+ <servlet-class>org.nuiton.test.topia.StopTest</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>StartTest</servlet-name>
+ <url-pattern>/start</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>StopTest</servlet-name>
+ <url-pattern>/stop</url-pattern>
+ </servlet-mapping>
+</web-app>
Property changes on: testTopiaPostgresError/trunk/src/main/webapp/WEB-INF/web.xml
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
1
0
r403 - in misctestproject/trunk: . src/main src/main/java/org/nuiton/test
by fdesbois@users.nuiton.org 07 Apr '10
by fdesbois@users.nuiton.org 07 Apr '10
07 Apr '10
Author: fdesbois
Date: 2010-04-07 17:58:23 +0200 (Wed, 07 Apr 2010)
New Revision: 403
Log:
- Add ConcatAlgo to test different algorithms for string concatenation -> add the best algo in join method in StringUtil in nuiton-utils
- Add StringArray to test some different ways to use String... in argument
Added:
misctestproject/trunk/src/main/java/org/nuiton/test/ConcatAlgo.java
misctestproject/trunk/src/main/java/org/nuiton/test/StringArray.java
misctestproject/trunk/src/main/resources/
Modified:
misctestproject/trunk/pom.xml
Modified: misctestproject/trunk/pom.xml
===================================================================
--- misctestproject/trunk/pom.xml 2010-03-15 11:48:25 UTC (rev 402)
+++ misctestproject/trunk/pom.xml 2010-04-07 15:58:23 UTC (rev 403)
@@ -66,7 +66,7 @@
<dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils</artifactId>
- <version>1.1.0</version>
+ <version>1.2.2-SNAPSHOT</version>
</dependency>
<dependency>
Added: misctestproject/trunk/src/main/java/org/nuiton/test/ConcatAlgo.java
===================================================================
--- misctestproject/trunk/src/main/java/org/nuiton/test/ConcatAlgo.java (rev 0)
+++ misctestproject/trunk/src/main/java/org/nuiton/test/ConcatAlgo.java 2010-04-07 15:58:23 UTC (rev 403)
@@ -0,0 +1,188 @@
+
+package org.nuiton.test;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.commons.lang.StringUtils;
+import org.nuiton.util.StringUtil;
+
+/**
+ *
+ * @author fdesbois
+ */
+public class ConcatAlgo {
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+
+ final long NB_ELMTS = 1000;
+ final long ELMT_SIZE = 100;
+ final long NB_EXECUTIONS = 1000;
+ final long ALGO4_TRESHOLD = 1000;
+
+ List<String> list = new ArrayList<String>();
+ long i;
+ for (i = 0; i < NB_ELMTS; i++) {
+ StringBuffer buffer = new StringBuffer();
+ for (int k = 0; k < ELMT_SIZE; k++) {
+ buffer.append("e");
+ }
+ list.add(buffer.toString());
+ }
+
+ long tic1, tic2;
+ String result;
+ long time1 = 0, time2 = 0, time3 = 0, time4 = 0, time5 = 0, time6 = 0,
+ time7 = 0;
+
+ for (long j = 0; j < NB_EXECUTIONS; j++) {
+
+ tic1 = System.currentTimeMillis();
+ result = algo1(list);
+ tic2 = System.currentTimeMillis();
+ time1 += (tic2 - tic1);
+
+ tic1 = System.currentTimeMillis();
+ result = algo2(list);
+ tic2 = System.currentTimeMillis();
+ time2 += (tic2 - tic1);
+
+ tic1 = System.currentTimeMillis();
+ result = algo3(list);
+ tic2 = System.currentTimeMillis();
+ time3 += (tic2 - tic1);
+
+ if (i < ALGO4_TRESHOLD) {
+ tic1 = System.currentTimeMillis();
+ result = algo4(list);
+ tic2 = System.currentTimeMillis();
+ time4 += (tic2 - tic1);
+ }
+
+ tic1 = System.currentTimeMillis();
+ result = algo5(list);
+ tic2 = System.currentTimeMillis();
+ time5 += (tic2 - tic1);
+
+ tic1 = System.currentTimeMillis();
+ result = algo6(list);
+ tic2 = System.currentTimeMillis();
+ time6 += (tic2 - tic1);
+
+ tic1 = System.currentTimeMillis();
+ result = algo6(list);
+ tic2 = System.currentTimeMillis();
+ time7 += (tic2 - tic1);
+ }
+
+ System.out.println("Nb elements = " + NB_ELMTS);
+ System.out.println("Element size = " + ELMT_SIZE);
+ System.out.println("Nb executions = " + NB_EXECUTIONS);
+ System.out.println("Algo1 average time = " + (time1 / NB_EXECUTIONS) +
+ " _ cumul = " + time1);
+ System.out.println("Algo2 average time = " + (time2 / NB_EXECUTIONS) +
+ " _ cumul = " + time2);
+ System.out.println("Algo3 average time = " + (time3 / NB_EXECUTIONS) +
+ " _ cumul = " + time3);
+ if (i < ALGO4_TRESHOLD) {
+ System.out.println("Algo4 average time = " +
+ (time4 / NB_EXECUTIONS) + " _ cumul = " + time4);
+ }
+ System.out.println("Algo5 average time = " + (time5 / NB_EXECUTIONS) +
+ " _ cumul = " + time5);
+ System.out.println("Algo6 average time = " + (time6 / NB_EXECUTIONS) +
+ " _ cumul = " + time6);
+ System.out.println("Algo7 average time = " + (time7 / NB_EXECUTIONS) +
+ " _ cumul = " + time7);
+ }
+
+ // buffer + iterator (if inside the for)
+ public static String algo1(List<String> list) {
+ // 10 rows
+ StringBuffer buffer = new StringBuffer();
+ for (Iterator<String> j = list.iterator(); j.hasNext();) {
+ String elmt = j.next();
+ buffer.append(elmt);
+ if (j.hasNext()) {
+ buffer.append(", ");
+ }
+ }
+ String result = buffer.toString();
+ buffer = null;
+ return result;
+ }
+
+ // buffer + foreach + substring
+ public static String algo2(List<String> list) {
+ // 10 rows
+ if (list.isEmpty()) {
+ return "";
+ }
+ StringBuffer buffer = new StringBuffer();
+ String separator = ", ";
+ for (String elmt : list) {
+ buffer.append(separator).append(elmt);
+ }
+ String result = buffer.substring(separator.length());
+ buffer = null;
+ return result;
+ }
+
+ // buffer + foreach + change separator param
+ public static String algo3(List<String> list) {
+ // 8 rows
+ StringBuffer buffer = new StringBuffer();
+ String separator = "";
+ for (String elmt : list) {
+ buffer.append(separator).append(elmt);
+ separator = ", ";
+ }
+ String result = buffer.toString();
+ buffer = null;
+ return result;
+ }
+
+ // no buffer + foreach + change separator param
+ public static String algo4(List<String> list) {
+ // 7 rows
+ String result = "";
+ String separator = "";
+ for (String elmt : list) {
+ result += separator + elmt;
+ separator = ", ";
+ }
+ return result;
+ }
+
+ // using stringUtils join
+ public static String algo5(List<String> list) {
+ // 2 rows
+ String result = StringUtils.join(list, ", ");
+ return result;
+ }
+
+ // algo3 with stringBuilder
+ public static String algo6(List<String> list) {
+ // 8 rows
+ StringBuilder builder = new StringBuilder();
+ String separator = "";
+ for (String elmt : list) {
+ builder.append(separator).append(elmt);
+ separator = ", ";
+ }
+ String result = builder.toString();
+ builder = null;
+ return result;
+ }
+
+ // algo6 using in StringUtil (nuiton-utils)
+ public static String algo7(List<String> list) {
+ // 2 rows
+ String result = StringUtil.join(list, ", ", false);
+ return result;
+ }
+
+}
Property changes on: misctestproject/trunk/src/main/java/org/nuiton/test/ConcatAlgo.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: misctestproject/trunk/src/main/java/org/nuiton/test/StringArray.java
===================================================================
--- misctestproject/trunk/src/main/java/org/nuiton/test/StringArray.java (rev 0)
+++ misctestproject/trunk/src/main/java/org/nuiton/test/StringArray.java 2010-04-07 15:58:23 UTC (rev 403)
@@ -0,0 +1,60 @@
+
+package org.nuiton.test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ *
+ * @author fdesbois
+ */
+public class StringArray {
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+ System.out.println("StringArray");
+ test2("Troulala", "Tartanpion", "Potiron");
+ test2("Troulala");
+ test3(new Object[]{ "Troubidou", "Wahou!"});
+ test3(new Object[]{ "Troubidou", "Wahou!"}, "Fouac");
+ Object[] params = new Object[2];
+ params[0] = "Troubidou";
+ params[1] = "Wahou!";
+ test3(params);
+ List<Object> plop = new ArrayList<Object>();
+ test3(plop.toArray());
+
+ plop.add("Troubidou");
+ test3(plop.toArray());
+ }
+
+ public static void test(String... param) {
+ String str = Arrays.toString(param);
+ System.out.println("toString : " + str.substring(1, str.length()-1));
+ }
+
+ public static void test2(String... param) {
+ StringBuilder result = new StringBuilder();
+ for (String value : param) {
+ result.append(", ").append(value);
+ }
+ String str = "";
+ if (result.length() > 0) {
+ str = result.substring(2);
+ }
+ System.out.println("toString : " + str);
+ }
+
+ public static void test3(Object... param) {
+ Object[] array = param;
+ System.out.println("toString : " + Arrays.toString(array));
+ for (Object o : param) {
+ System.out.println("elmt : " + o);
+ }
+ System.out.println("nbElmts : " + array.length);
+ }
+
+}
Property changes on: misctestproject/trunk/src/main/java/org/nuiton/test/StringArray.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
1
0