Isis-fish-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
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- 3175 discussions
r1739 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher
by chatellier@users.labs.libre-entreprise.org 14 Jan '09
by chatellier@users.labs.libre-entreprise.org 14 Jan '09
14 Jan '09
Author: chatellier
Date: 2009-01-14 14:22:05 +0000 (Wed, 14 Jan 2009)
New Revision: 1739
Added:
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHUtils.java
Modified:
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncher.java
Log:
Move ssh specific code to utility class.
Use ANT optionnal ssh task code (better than jsch samples)
Download simulation result when simulation complete.
Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHUtils.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHUtils.java (rev 0)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHUtils.java 2009-01-14 14:22:05 UTC (rev 1739)
@@ -0,0 +1,495 @@
+/* *##%
+ * Copyright (C) 2008 Code Lutin
+ *
+ * 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 2
+ * 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 Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package fr.ifremer.isisfish.simulator.launcher;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.jcraft.jsch.Channel;
+import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+
+/**
+ * SSH utils class.
+ *
+ * All this code has be taken from ant optionnal ssh task.
+ *
+ * Use full for:
+ * - scpTo command
+ * - scpFrom command
+ * - exec command
+ *
+ * @author chatellier
+ * @version $Revision: 1.0 $
+ *
+ * Last update : $Date: 13 janv. 2009 $
+ * By : $Author: chatellier $
+ */
+public class SSHUtils {
+
+ /** log. */
+ private static Log log = LogFactory.getLog(SSHUtils.class);
+
+ protected static final byte LINE_FEED = 0x0a;
+ protected static final int BUFFER_SIZE = 1024;
+ private static final int HUNDRED_KILOBYTES = 102400;
+
+ /** Utility class */
+ protected SSHUtils() {
+
+ }
+
+ /**
+ * Exec command on remote server.
+ *
+ * @param session opened valid session
+ * @param command command to exec
+ * @throws SSHException
+ */
+ public static void exec(Session session, String command)
+ throws SSHException {
+
+ try {
+ // exec previous command
+ Channel channel = session.openChannel("exec");
+ ((ChannelExec) channel).setCommand(command);
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ channel.getInputStream()));
+ channel.connect();
+ String line = null;
+ while (true) {
+ while ((line = br.readLine()) != null) {
+ if (log.isInfoEnabled()) {
+ log.info("Remote output : " + line);
+ }
+ }
+ if (channel.isClosed()) {
+ if (log.isInfoEnabled()) {
+ log.info("JSch channel exit-status: "
+ + channel.getExitStatus());
+ }
+ break;
+ }
+ try {
+ Thread.sleep(500);
+ } catch (Exception ee) {
+ }
+ }
+ channel.disconnect();
+ // end read buffer
+ } catch (JSchException e) {
+ throw new SSHException("I/O error while executing command", e);
+ } catch (IOException e) {
+ throw new SSHException("I/O error while executing command", e);
+ }
+
+ }
+
+ /**
+ * Download a local file from remote server.
+ *
+ * @param session opened valid jsch session
+ * @param remoteFileName remote file name to download
+ * @param localFile local file name to download into
+ *
+ * @throws SSHException
+ */
+ public static void scpFrom(Session session, String remoteFileName,
+ File localFile) throws SSHException {
+
+ String command = "scp -f -r \"" + remoteFileName + "\"";
+
+ ChannelExec channel = null;
+ try {
+ channel = (ChannelExec) session.openChannel("exec");
+ channel.setCommand(command);
+
+ // get I/O streams for remote scp
+ OutputStream out = channel.getOutputStream();
+ InputStream in = channel.getInputStream();
+
+ channel.connect();
+
+ sendAck(out);
+ startRemoteCpProtocol(in, out, localFile);
+ } catch (IOException e) {
+ throw new SSHException(e);
+ } catch (JSchException e) {
+ throw new SSHException(e);
+ } finally {
+ if (channel != null) {
+ channel.disconnect();
+ }
+ }
+ }
+
+ /**
+ * Upload file on remote server.
+ *
+ * @param session opened valid session
+ * @param localFile file to upload
+ * @param remoteFilePath remote file path
+ *
+ * @throws SSHException
+ */
+ public static void scpTo(Session session, File localFile,
+ String remoteFilePath) throws SSHException {
+
+ try {
+ doSingleTransfer(session, localFile, remoteFilePath);
+ } catch (IOException e) {
+ throw new SSHException(e);
+ } catch (JSchException e) {
+ throw new SSHException(e);
+ }
+ }
+
+ /**
+ * Send an ack.
+ * @param out the output stream to use
+ * @throws IOException on error
+ */
+ protected static void sendAck(OutputStream out) throws IOException {
+ byte[] buf = new byte[1];
+ buf[0] = 0;
+ out.write(buf);
+ out.flush();
+ }
+
+ /**
+ * Reads the response, throws a BuildException if the response
+ * indicates an error.
+ * @param in the input stream to use
+ * @throws IOException on I/O error
+ */
+ protected static void waitForAck(InputStream in) throws IOException,
+ SSHException {
+ int b = in.read();
+
+ // b may be 0 for success,
+ // 1 for error,
+ // 2 for fatal error,
+
+ if (b == -1) {
+ // didn't receive any response
+ throw new SSHException("No response from server");
+ } else if (b != 0) {
+ StringBuffer sb = new StringBuffer();
+
+ int c = in.read();
+ while (c > 0 && c != '\n') {
+ sb.append((char) c);
+ c = in.read();
+ }
+
+ if (b == 1) {
+ throw new SSHException("server indicated an error: "
+ + sb.toString());
+ } else if (b == 2) {
+ throw new SSHException("server indicated a fatal error: "
+ + sb.toString());
+ } else {
+ throw new SSHException("unknown response, code " + b
+ + " message: " + sb.toString());
+ }
+ }
+ }
+
+ /**
+ * Track progress every 10% if 100kb < filesize < 1mb. For larger
+ * files track progress for every percent transmitted.
+ * @param filesize the size of the file been transmitted
+ * @param totalLength the total transmission size
+ * @param percentTransmitted the current percent transmitted
+ * @return the percent that the file is of the total
+ */
+ protected static int trackProgress(long filesize, long totalLength,
+ int percentTransmitted) {
+
+ // CheckStyle:MagicNumber OFF
+ int percent = (int) Math.round(Math
+ .floor((totalLength / (double) filesize) * 100));
+
+ if (percent > percentTransmitted) {
+ if (filesize < 1048576) {
+ if (percent % 5 == 0) {
+ if (percent == 100) {
+ System.out.println(" 100%");
+ } else {
+ System.out.print("*");
+ }
+ }
+ } else {
+ if (percent == 50) {
+ System.out.println(" 50%");
+ } else if (percent == 100) {
+ System.out.println(" 100%");
+ } else {
+ System.out.print(".");
+ }
+ }
+ }
+ // CheckStyle:MagicNumber ON
+
+ return percent;
+ }
+
+ protected static void startRemoteCpProtocol(InputStream in,
+ OutputStream out, File localFile) throws IOException, SSHException {
+ File startFile = localFile;
+ while (true) {
+ // C0644 filesize filename - header for a regular file
+ // T time 0 time 0\n - present if perserve time.
+ // D directory - this is the header for a directory.
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ while (true) {
+ int read = in.read();
+ if (read < 0) {
+ return;
+ }
+ if ((byte) read == LINE_FEED) {
+ break;
+ }
+ stream.write(read);
+ }
+ String serverResponse = stream.toString("UTF-8");
+ if (serverResponse.charAt(0) == 'C') {
+ parseAndFetchFile(serverResponse, startFile, out, in);
+ } else if (serverResponse.charAt(0) == 'D') {
+ startFile = parseAndCreateDirectory(serverResponse, startFile);
+ sendAck(out);
+ } else if (serverResponse.charAt(0) == 'E') {
+ startFile = startFile.getParentFile();
+ sendAck(out);
+ } else if (serverResponse.charAt(0) == '\01'
+ || serverResponse.charAt(0) == '\02') {
+ // this indicates an error.
+ throw new IOException(serverResponse.substring(1));
+ }
+ }
+ }
+
+ protected static File parseAndCreateDirectory(String serverResponse,
+ File localFile) {
+ int start = serverResponse.indexOf(" ");
+ // appears that the next token is not used and it's zero.
+ start = serverResponse.indexOf(" ", start + 1);
+ String directoryName = serverResponse.substring(start + 1);
+ if (localFile.isDirectory()) {
+ File dir = new File(localFile, directoryName);
+ dir.mkdir();
+ log.debug("Creating: " + dir);
+ return dir;
+ }
+ return null;
+ }
+
+ protected static void parseAndFetchFile(String serverResponse,
+ File localFile, OutputStream out, InputStream in)
+ throws IOException, SSHException {
+ int start = 0;
+ int end = serverResponse.indexOf(" ", start + 1);
+ start = end + 1;
+ end = serverResponse.indexOf(" ", start + 1);
+ long filesize = Long.parseLong(serverResponse.substring(start, end));
+ String filename = serverResponse.substring(end + 1);
+ log.debug("Receiving: " + filename + " : " + filesize);
+ File transferFile = (localFile.isDirectory()) ? new File(localFile,
+ filename) : localFile;
+ fetchFile(transferFile, filesize, out, in);
+ waitForAck(in);
+ sendAck(out);
+ }
+
+ protected static void fetchFile(File localFile, long filesize,
+ OutputStream out, InputStream in) throws IOException {
+ byte[] buf = new byte[BUFFER_SIZE];
+ sendAck(out);
+
+ // read a content of lfile
+ FileOutputStream fos = new FileOutputStream(localFile);
+ int length;
+ long totalLength = 0;
+
+ // only track progress for files larger than 100kb in verbose mode
+ boolean trackProgress = filesize > HUNDRED_KILOBYTES;
+ // since filesize keeps on decreasing we have to store the
+ // initial filesize
+ long initFilesize = filesize;
+ int percentTransmitted = 0;
+
+ try {
+ while (true) {
+ length = in.read(buf, 0, (BUFFER_SIZE < filesize) ? BUFFER_SIZE
+ : (int) filesize);
+ if (length < 0) {
+ throw new EOFException("Unexpected end of stream.");
+ }
+ fos.write(buf, 0, length);
+ filesize -= length;
+ totalLength += length;
+ if (filesize == 0) {
+ break;
+ }
+
+ if (trackProgress) {
+ percentTransmitted = trackProgress(initFilesize,
+ totalLength, percentTransmitted);
+ }
+ }
+ } finally {
+ fos.flush();
+ fos.close();
+ }
+ }
+
+ protected static void doSingleTransfer(Session session, File localFile,
+ String remoteFilePath) throws IOException, JSchException,
+ SSHException {
+
+ String command = "scp -t \"" + remoteFilePath + "\"";
+ ChannelExec channel = (ChannelExec) session.openChannel("exec");
+ channel.setCommand(command);
+ try {
+
+ OutputStream out = channel.getOutputStream();
+ InputStream in = channel.getInputStream();
+
+ channel.connect();
+
+ waitForAck(in);
+ sendFileToRemote(localFile, in, out);
+ } finally {
+ channel.disconnect();
+ }
+ }
+
+ protected static void sendFileToRemote(File localFile, InputStream in,
+ OutputStream out) throws IOException, SSHException {
+ // send "C0644 filesize filename", where filename should not include '/'
+ long filesize = localFile.length();
+ String command = "C0644 " + filesize + " ";
+ command += localFile.getName();
+ command += "\n";
+
+ out.write(command.getBytes());
+ out.flush();
+
+ waitForAck(in);
+
+ // send a content of lfile
+ FileInputStream fis = new FileInputStream(localFile);
+ byte[] buf = new byte[BUFFER_SIZE];
+ long totalLength = 0;
+
+ // only track progress for files larger than 100kb in verbose mode
+ boolean trackProgress = filesize > HUNDRED_KILOBYTES;
+ // since filesize keeps on decreasing we have to store the
+ // initial filesize
+ long initFilesize = filesize;
+ int percentTransmitted = 0;
+
+ try {
+ while (true) {
+ int len = fis.read(buf, 0, buf.length);
+ if (len <= 0) {
+ break;
+ }
+ out.write(buf, 0, len);
+ totalLength += len;
+
+ if (trackProgress) {
+ percentTransmitted = trackProgress(initFilesize,
+ totalLength, percentTransmitted);
+ }
+ }
+ out.flush();
+ sendAck(out);
+ waitForAck(in);
+ } finally {
+ fis.close();
+ }
+ }
+}
+
+/**
+ * SSHException.
+ *
+ * @author chatellier
+ * @version $Revision: 1.0 $
+ *
+ * Last update : $Date: 14 janv. 2009 $
+ * By : $Author: chatellier $
+ */
+class SSHException extends Exception {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -198651402309210758L;
+
+ /**
+ * Constructs a new exception with null as its detail message.
+ */
+ public SSHException() {
+ super();
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message.
+ *
+ * @param message message
+ * @param cause cause
+ */
+ public SSHException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and cause.
+ *
+ * @param message message
+ */
+ public SSHException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new exception with the specified cause and a detail message
+ * of (cause==null ? null : cause.toString()) (which typically contains the
+ * class and detail message of cause).
+ *
+ * @param cause cause
+ */
+ public SSHException(Throwable cause) {
+ super(cause);
+ }
+
+}
\ No newline at end of file
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncher.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncher.java 2009-01-13 19:48:00 UTC (rev 1738)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SshSimulatorLauncher.java 2009-01-14 14:22:05 UTC (rev 1739)
@@ -25,11 +25,7 @@
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.rmi.RemoteException;
import java.util.List;
@@ -43,8 +39,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import com.jcraft.jsch.Channel;
-import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
@@ -132,11 +126,16 @@
// si l'upload a fonctionné
if (remotePath != null) {
message(control, _("isisfish.simulation.remote.message.launch"));
+
// just start a thread
checkSimulationProgression(sshSession, simulationService,
control);
launchSimulation(sshSession, simulationService, control,
remotePath);
+
+ // recuperation des resultats
+ message(control, _("isisfish.simulation.remote.message.downloadresults"));
+ downloadResults(sshSession, control.getId());
// force thread to stop
synchronized(control) {
@@ -262,38 +261,7 @@
log.debug("command is : " + command);
}
- // exec previous commande
- Channel channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
-
- // read buffer
- // seems to not work without it
- InputStream in = channel.getInputStream();
- channel.connect();
- byte[] tmp = new byte[1024];
- while (true) {
- while (in.available() > 0) {
- int i = in.read(tmp, 0, 1024);
- if (i < 0)
- break;
- if (log.isInfoEnabled()) {
- log.info(new String(tmp, 0, i));
- }
- }
- if (channel.isClosed()) {
- if (log.isInfoEnabled()) {
- log.info("JSch channel exit-status: "
- + channel.getExitStatus());
- }
- break;
- }
- try {
- Thread.sleep(1000);
- } catch (Exception ee) {
- }
- }
- channel.disconnect();
- // end read buffer
+ SSHUtils.exec(session, command);
}
} catch (IOException e) {
if (log.isErrorEnabled()) {
@@ -301,14 +269,17 @@
e);
}
}
+ catch (SSHException e) {
+ if (log.isErrorEnabled()) {
+ log.error(_("Error while uploading public key to remote serveur authorized_keys"),
+ e);
+ }
+ }
}
/**
* Upload simulation file to server.
*
- * ScpTo code taken from :
- * http://www.jcraft.com/jsch/examples/ScpTo.java
- *
* @param session already open valid ssh session
* @param simulationFile simulation file to upload
*
@@ -316,141 +287,78 @@
*/
protected String uploadSimulation(Session session, File simulationFile) {
- // return flag
- String remotePath = null;
+ String localPath = simulationFile.getAbsolutePath();
+
+ // Copy simulation file in same arch as local arch
+ // on windows, it's a bad idee :)))
+ // copy it always on caparmor remote temp dir ?
+ // /tmp ?
+ // TODO check it
- // file info
- String filePath = simulationFile.getAbsolutePath();
+ String remotePath = "/tmp/";
- FileInputStream fis = null;
- try {
+ if(localPath.lastIndexOf("/") > 0) {
+ remotePath += localPath.substring(localPath.lastIndexOf("/") + 1);
+ }
+ else if(localPath.lastIndexOf("\\") > 0) { // windows
+ remotePath += localPath.substring(localPath.lastIndexOf("\\") + 1);
+ }
+ else {
+ remotePath += localPath;
+ }
- // exec 'scp -t rfile' remotely
- String command = "scp -p -t " + filePath;
- Channel channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
-
- // get I/O streams for remote scp
- OutputStream out = channel.getOutputStream();
- InputStream in = channel.getInputStream();
-
- channel.connect();
-
- // Check input stream validity
- if (checkAck(in) == 0) {
-
- if (log.isDebugEnabled()) {
- log.debug("Uploading " + filePath);
- }
-
- // send "C0644 filesize filename", where filename should not include '/'
- long filesize = (new File(filePath)).length();
- command = "C0644 " + filesize + " ";
- if (filePath.lastIndexOf('/') > 0) {
- command += filePath
- .substring(filePath.lastIndexOf('/') + 1);
- } else {
- command += filePath;
- }
- command += "\n";
- out.write(command.getBytes());
- out.flush();
-
- if (checkAck(in) == 0) {
-
- // send a content of lfile
- fis = new FileInputStream(filePath);
- byte[] buf = new byte[1024];
- while (true) {
- int len = fis.read(buf, 0, buf.length);
- if (len <= 0) {
- break;
- }
- out.write(buf, 0, len); //out.flush();
- }
- fis.close();
- fis = null;
- // send '\0'
- buf[0] = 0;
- out.write(buf, 0, 1);
- out.flush();
- if (checkAck(in) == 0) {
- remotePath = filePath;
- }
- out.close();
-
- channel.disconnect();
- }
- }
-
- } catch (JSchException e) {
+ try {
+ SSHUtils.scpTo(session, simulationFile, remotePath);
+ }
+ catch(SSHException e) {
if (log.isErrorEnabled()) {
- log.error(_("isisfish.error.simulation.remote.upload",
- filePath));
+ log.error(_("Error while uploading simulation"),
+ e);
}
- } catch (IOException e) {
- if (log.isErrorEnabled()) {
- log.error(_("isisfish.error.simulation.remote.upload",
- filePath));
- }
- } finally {
- try {
- if (fis != null) {
- fis.close();
- }
- } catch (IOException e) {
- // exception ignoree
- }
+
+ remotePath = null;
}
return remotePath;
}
/**
- * Check input stream validity.
+ * Download resulation results.
*
- * Code taken from Jsch samples.
- *
- * @param in input stream
+ * @return downloaded temp file (file have to be manually deleted)
*/
- protected int checkAck(InputStream in) throws IOException {
- int b = in.read();
- // b may be 0 for success,
- // 1 for error,
- // 2 for fatal error,
- // -1
- if (b == 0) {
- return b;
+ protected File downloadResults(Session session, String simulationId) {
+
+ // simulation directory
+ File localFile = new File(IsisFish.config.getDatabaseDirectory(),
+ SimulationStorage.SIMULATION_PATH);
+
+ if(log.isDebugEnabled()) {
+ log.debug("Downloading results in " + localFile.getAbsolutePath());
}
- if (b == -1) {
- return b;
- }
+
+ // build remote file path
+ // FIXME this path should be given by remote IsisFish app
+ // TODO to change
+ String remoteFile = IsisFish.config.getSimulatorSshDataPath();
+ remoteFile += "/" + SimulationStorage.SIMULATION_PATH;
+ remoteFile += "/" + simulationId;
- if (b == 1 || b == 2) {
- StringBuffer sb = new StringBuffer();
- int c;
- do {
- c = in.read();
- sb.append((char) c);
- } while (c != '\n');
- if (b == 1) { // error
- if (log.isErrorEnabled()) {
- log.error(_(
- "isisfish.error.simulation.remote.upload.stream",
- sb.toString()));
- }
+ try {
+ SSHUtils.scpFrom(session, remoteFile, localFile);
+ }
+ catch(SSHException e) {
+ // error can append because control file does'nt exist yet
+ if (log.isDebugEnabled()) {
+ log.debug(_("Error while downloading simulation control"));
}
- if (b == 2) { // fatal error
- if (log.isFatalEnabled()) {
- log.fatal(_(
- "isisfish.error.simulation.remote.upload.stream",
- sb.toString()));
- }
- }
+
+ localFile = null;
}
- return b;
+
+ return localFile;
}
-
+
/**
* Launch simulation on remote server.
*
@@ -477,44 +385,15 @@
if (log.isDebugEnabled()) {
log.debug("Launch : " + command);
}
-
- Channel channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
-
- channel.setInputStream(null);
-
+
try {
- InputStream in = channel.getInputStream();
-
- channel.connect();
-
- byte[] tmp = new byte[1024];
- while (true) {
- while (in.available() > 0) {
- int i = in.read(tmp, 0, 1024);
- if (i < 0) {
- break;
- }
- if (log.isInfoEnabled()) {
- log.info(_("isisfish.error.simulation.remote.output") + new String(tmp, 0, i));
- }
- }
- if (channel.isClosed()) {
- if (log.isInfoEnabled()) {
- log.info("JSch channel exit-status: "
- + channel.getExitStatus());
- }
- break;
- }
- try {
- Thread.sleep(1000);
- } catch (Exception ee) {
- }
+ SSHUtils.exec(session, command);
+ }
+ catch(SSHException e) {
+ if (log.isErrorEnabled()) {
+ log.error(_("Error while launching simulation"),
+ e);
}
- channel.disconnect();
- } catch (IOException e) {
- throw new SimulationException(
- _("isisfish.error.simulation.remote.launch"), e);
}
}
@@ -623,9 +502,6 @@
* Download remote simulation control file and store
* its content into temp file.
*
- * ScpFrom code taken from :
- * http://www.jcraft.com/jsch/examples/ScpFrom.java
- *
* @return downloaded temp file (file have to be manually deleted)
* @throws IOException
*/
@@ -643,123 +519,19 @@
remoteFile += "/control";
// local tmp file
- File tempFile = File.createTempFile(simulationId, "control");
- FileOutputStream fos=null;
-
+ localFile = File.createTempFile(simulationId, "control");
+
try {
- // exec 'scp -f rfile' remotely
- String command = "scp -f \"" + remoteFile + "\"";
- Channel channel = sshSession.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
-
- // get I/O streams for remote scp
- OutputStream out = channel.getOutputStream();
- InputStream in = channel.getInputStream();
-
- channel.connect();
-
- byte[] buf = new byte[1024];
-
- // send '\0'
- buf[0] = 0;
- out.write(buf, 0, 1);
- out.flush();
-
- while (true) {
- int c = checkAck(in);
- if (c != 'C') {
- break;
- }
-
- // read '0644 '
- in.read(buf, 0, 5);
-
- long filesize = 0L;
- while (true) {
- if (in.read(buf, 0, 1) < 0) {
- // error
- break;
- }
- if (buf[0] == ' ') {
- break;
- }
- filesize = filesize * 10L + (buf[0] - '0');
- }
-
- //String file = null;
- for (int i = 0;; i++) {
- in.read(buf, i, 1);
- if (buf[i] == (byte) 0x0a) {
- //file = new String(buf, 0, i);
- break;
- }
- }
-
- // send '\0'
- buf[0] = 0;
- out.write(buf, 0, 1);
- out.flush();
-
- // read a content of lfile
- fos = new FileOutputStream(tempFile);
- int foo;
- while (true) {
- if (buf.length < filesize) {
- foo = buf.length;
- }
- else {
- foo = (int) filesize;
- }
- foo = in.read(buf, 0, foo);
- if (foo < 0) {
- // error
- break;
- }
- fos.write(buf, 0, foo);
- filesize -= foo;
- if (filesize == 0L) {
- break;
- }
- }
- fos.close();
- fos = null;
-
- if (checkAck(in) == 0) {
- localFile = tempFile;
- }
-
- // send '\0'
- buf[0] = 0;
- out.write(buf, 0, 1);
- out.flush();
- }
+ SSHUtils.scpFrom(sshSession, remoteFile, localFile);
}
- catch(IOException e){
- if(log.isErrorEnabled()) {
- log.error("I/O error while downloading control file", e);
+ catch(SSHException e) {
+ if (log.isErrorEnabled()) {
+ log.error(_("Error while launching simulation"),
+ e);
}
- } catch (JSchException e) {
- if(log.isErrorEnabled()) {
- log.error("Jsch error while downloading control file", e);
- }
+ localFile = null;
}
- finally {
- try{
- if(fos!=null) {
- fos.close();
- }
- }
- catch(Exception ignored) {
- }
- }
-
- if(localFile == null) {
- // an arror occurs
- // so remove temp file
- tempFile.delete();
- }
-
return localFile;
}
}
1
0
r1738 - in isis-fish/trunk: . src/test/java/fr/ifremer src/test/java/fr/ifremer/isisfish/entity src/test/java/fr/ifremer/isisfish/logging src/test/java/fr/ifremer/isisfish/logging/io src/test/java/fr/ifremer/isisfish/simulator
by tchemit@users.labs.libre-entreprise.org 13 Jan '09
by tchemit@users.labs.libre-entreprise.org 13 Jan '09
13 Jan '09
Author: tchemit
Date: 2009-01-13 19:48:00 +0000 (Tue, 13 Jan 2009)
New Revision: 1738
Added:
isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java
Modified:
isis-fish/trunk/pom.xml
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/SimulationLoggerUtilTest.java
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/TestUtil.java
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderTest.java
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderUtilTest.java
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationHelperTest.java
Log:
suis pass?\195?\169 dans le coin et j'ai vu que y'avait plus beaucoup de test qui passaient...
il faut laisser les tester m?\195?\170me s'il y a des erreurs...
Modified: isis-fish/trunk/pom.xml
===================================================================
--- isis-fish/trunk/pom.xml 2009-01-13 16:51:24 UTC (rev 1737)
+++ isis-fish/trunk/pom.xml 2009-01-13 19:48:00 UTC (rev 1738)
@@ -332,12 +332,8 @@
<!--Main class in JAR -->
<maven.jar.main.class>fr.ifremer.isisfish.IsisFish</maven.jar.main.class>
- <!-- for the moment skip tests -->
- <maven.test.skip>true</maven.test.skip>
-
- <!-- FIXE should at leaste be this !-->
<!-- Ignore failure test for now -->
- <!--maven.test.testFailureIgnore>true</maven.test.testFailureIgnore-->
+ <maven.test.testFailureIgnore>true</maven.test.testFailureIgnore>
<!-- jnlp -->
<keystorepath>../../../CodeLutinKeystore</keystorepath>
Added: isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java (rev 0)
+++ isis-fish/trunk/src/test/java/fr/ifremer/TestUtils.java 2009-01-13 19:48:00 UTC (rev 1738)
@@ -0,0 +1,35 @@
+package fr.ifremer;
+
+import java.io.File;
+
+/**
+ * Une classe pour avoir des choses utiles pour tous les tests d'isis
+ *
+ * @author chemit
+ */
+public abstract class TestUtils {
+
+ static File basedir;
+
+ static File targetdir;
+
+ public static File getBasedir() {
+ if (basedir == null) {
+ String base = System.getProperty("basedir");
+ if (base == null || base.isEmpty()) {
+ base = new File("").getAbsolutePath();
+ }
+ basedir = new File(base);
+ System.out.println("basedir for test " + basedir);
+ }
+ return basedir;
+ }
+
+ public static File getTargetdir() {
+ if (targetdir == null) {
+ targetdir = new File(getBasedir(), "target");
+ System.out.println("targetdir for test " + targetdir);
+ }
+ return targetdir;
+ }
+}
Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java 2009-01-13 16:51:24 UTC (rev 1737)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/entity/PopulationSeasonInfoTest.java 2009-01-13 19:48:00 UTC (rev 1738)
@@ -36,9 +36,12 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.awt.event.WindowEvent;
import javax.swing.Box;
import javax.swing.JOptionPane;
+import javax.swing.JDialog;
+import javax.swing.SwingUtilities;
import junit.framework.TestCase;
@@ -53,8 +56,7 @@
*
*/
-public class PopulationSeasonInfoTest extends TestCase {
-
+public class PopulationSeasonInfoTest extends TestCase {
public void testToString() {
String [] s = new String[]{"toto", "titi", "tutu"};
System.out.println(Arrays.toString(s));
@@ -63,20 +65,20 @@
/*
* Test method for 'fr.ifremer.isisfish.entities.PopulationSeasonInfoImpl.getGroupChangeMatrix(Month)'
*/
- public void testGetGroupChangeMatrix() {
+ public void testGetGroupChangeMatrix() throws InterruptedException {
System.out.println("begin");
int nbrAge = 3;
int nbrZone = 2;
boolean groupplus = true;
List<String> sem = new ArrayList<String>();
-
+
for (int i=0; i<nbrAge; i++) {
for (int j=0; j<nbrZone; j++) {
sem.add("g" + i + "/z" + j);
- }
+ }
}
-
+
MatrixND mat = MatrixFactory.getInstance().create(new List[]{sem, sem});
for(MatrixIterator mi=mat.iterator(); mi.next();){
int [] dim = mi.getCoordinates();
@@ -91,25 +93,49 @@
// regarde si on est bien dans le dernier block
&& (nbrAge-1 == i/nbrZone)
// regarde si on est bien sur la diagonal
- && (i == j))
+ && (i == j))
){
mi.setValue(1);
}
}
-
- MatrixPanelEditor panel = new MatrixPanelEditor(false, 800, 300);
+
+ final MatrixPanelEditor panel = new MatrixPanelEditor(false, 800, 300);
panel.setMatrix(mat);
- JOptionPane.showMessageDialog(null, panel,
- _("Spacialized visualisation"), JOptionPane.INFORMATION_MESSAGE);
+ final JDialog dialog = new JDialog();
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ JOptionPane.showMessageDialog(dialog, panel,_("Spacialized visualisation"), JOptionPane.INFORMATION_MESSAGE);
+
+ }
+ });
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ dialog.dispose();
+ }
+ });
+ t.start();
+
+ // it would really be nice to wait the thread, otherwise the test
+ // means nothing!!!
+ t.join();
+
+
+
System.out.println("end");
}
/**
* Converte no spacialized matrix to spacialized matrix
*/
- public void testSpacializeLengthChangeMatrix() {
-
-
+ public void testSpacializeLengthChangeMatrix() throws InterruptedException {
+
+
int nbsecteurs = 2;
int nbclasses = 3;
@@ -118,15 +144,15 @@
for (MatrixIterator mi=mat.iterator(); mi.next();) {
mi.setValue(i++);
}
-
+
List<String> sem = new ArrayList<String>();
-
+
for (i=0; i<nbclasses; i++) {
for (int j=0; j<nbsecteurs; j++) {
sem.add("g" + i + "/z" + j);
- }
+ }
}
-
+
MatrixND bigmat = MatrixFactory.getInstance().create(new List[]{sem, sem});
for(i=0; i<nbclasses; i++){
@@ -141,17 +167,38 @@
panel.setMatrix(mat);
MatrixPanelEditor bigpanel = new MatrixPanelEditor(false, 800, 300);
bigpanel.setMatrix(bigmat);
-
- Box box = Box.createVerticalBox();
+
+ final Box box = Box.createVerticalBox();
box.add(panel);
box.add(bigpanel);
-
- JOptionPane.showMessageDialog(null, box,
- _("Spacialized visualisation"), JOptionPane.INFORMATION_MESSAGE);
+
+ final JDialog dialog = new JDialog();
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ JOptionPane.showMessageDialog(dialog, box, _("Spacialized visualisation"), JOptionPane.INFORMATION_MESSAGE);
+ }
+ });
+
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ dialog.dispose();
+ }
+ });
+ t.start();
+
+ // it would really be nice to wait the thread, otherwise the test
+ // means nothing!!!
+ t.join();
System.out.println("end");
}
-
+
}
Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/SimulationLoggerUtilTest.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/SimulationLoggerUtilTest.java 2009-01-13 16:51:24 UTC (rev 1737)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/SimulationLoggerUtilTest.java 2009-01-13 19:48:00 UTC (rev 1738)
@@ -1,6 +1,7 @@
package fr.ifremer.isisfish.logging;
+import fr.ifremer.TestUtils;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
@@ -17,7 +18,7 @@
static private final String category = "fr.ifremer.isisfish.logging";
- static private final String appenderId = "myLogger_" + System.currentTimeMillis();
+ static private final String appenderId = category+"."+"myLogger_" + System.currentTimeMillis();
static private Log log = LogFactory.getLog(category);
@@ -31,9 +32,9 @@
List<String> messagesToWrite = new ArrayList<String>();
List<String> messagesToSkip = new ArrayList<String>();
- logInfo(logInit, "before new config", null,null);
- logInfo(logInit2, "before new config", null,null);
- logInfo(log, "before new config", null,null);
+ logInfo(logInit, "before new config", null, null);
+ logInfo(logInit2, "before new config", null, null);
+ logInfo(log, "before new config", null, null);
String threadName = Thread.currentThread().getName();
@@ -43,7 +44,9 @@
Level hibernateLogLevel = hibernatelog.getLevel();
- String loggerFile = "testLog.log";
+ String loggerFile = new File(TestUtils.getTargetdir(), SimulationLoggerUtilTest.class.getSimpleName() + "_" + System.nanoTime() + ".log").getAbsolutePath();
+ System.out.println(">>>> loggerFile " + loggerFile);
+
// todo do a test for addSimulationAppender too!
SimulationLoggerUtil.addSimulationAppender(
loggerFile,
@@ -67,10 +70,10 @@
hibernatelog.fatal(message);
messagesToWrite.add(message);
- logInfo(logInit, "after new config using old logger", messagesToWrite,messagesToSkip);
+ logInfo(logInit, "after new config using old logger", messagesToWrite, messagesToSkip);
- logInfo(logger, "after new config using new logger", messagesToWrite,messagesToSkip);
- logInfo(log, "after new config using new logger", messagesToWrite,messagesToSkip);
+ logInfo(logger, "after new config using new logger", messagesToWrite, messagesToSkip);
+ logInfo(log, "after new config using new logger", messagesToWrite, messagesToSkip);
final String message0 = "BLOCK LOG must not appear in log file !!! since coming from another thread";
messagesToSkip.add(message0);
@@ -111,13 +114,14 @@
log.info("-- nb messages skipped : " + messagesToSkip.size());
log.info("-- nb messages written : " + messagesToWrite.size());
-
+ System.out.println("test messages to be skipped");
for (String s : messagesToSkip) {
- Assert.assertTrue(logFileContent.indexOf(s) == -1);
+ Assert.assertTrue("should not have write this entry : '" + s + "'", logFileContent.indexOf(s) == -1);
}
+ System.out.println("test messages to be written");
for (String s : messagesToWrite) {
- Assert.assertTrue(s, logFileContent.indexOf(s) > -1);
+ Assert.assertTrue("should have write this entry : '" + s + "'", logFileContent.indexOf(s) > -1);
}
logFile.delete();
@@ -256,6 +260,7 @@
messagesToWrite.add(message);
}
}
+
private void logDebug(Log logger, String prefix, List<String> messagesToWrite) {
String message;
Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/TestUtil.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/TestUtil.java 2009-01-13 16:51:24 UTC (rev 1737)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/TestUtil.java 2009-01-13 19:48:00 UTC (rev 1738)
@@ -10,6 +10,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
/**
* Usefull methods for tests.
@@ -17,7 +18,7 @@
* @author chemit
*/
-public class TestUtil {
+public abstract class TestUtil {
public static String filename;
public static long MEGA_STREAM_SIZE = 6 * 100000;
@@ -25,6 +26,19 @@
protected static final Log log = LogFactory.getLog(TestUtil.class);
+ public static void createMock(File testDir, String filename, int i) throws IOException, InterruptedException {
+ TestUtil.MEGA_STREAM_SIZE = 6 * i;
+ TestUtil.filename = new File(testDir, filename).getAbsolutePath();
+ File file = new File(testDir, filename);
+ long t0 = System.nanoTime();
+ mockLogFile();
+ long t1;
+
+ t1 = System.nanoTime();
+ log.info("create [" + TestUtil.MEGA_STREAM_SIZE + "] in " + StringUtil.convertTime(t1 - t0) + " [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "]");
+ System.gc();
+ }
+
static void pause(long time) throws InterruptedException {
Thread.sleep(time);
totalPause += time;
@@ -59,16 +73,100 @@
}
t1 = System.currentTimeMillis();
- log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1-t0) + " | total " + i + " in " + StringUtil.convertTime( t1 - totalPause-t00));
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
//pause(500);
t0 = System.currentTimeMillis();
for (i = MAX_0; i < 2 * MAX_0; i++) {
+ LogRecord record = LogRecord.newInstance(LogLevel.WARN, 0, i + " warn", "jkljfdjkl fdkjlkj lkjdlkfjl dfkljl dflkfdj lfdjlk fjdlkj fdl", "vmfof o rieipk?prj,anklvndfkljn gmlrtsoijrmoig", i, new String[0]);
+ s.write(record.toString() + '\n');
+ }
+ t1 = System.currentTimeMillis();
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
+ //pause(500);
+ t0 = System.currentTimeMillis();
+ for (i = 2 * MAX_0; i < 3 * MAX_0; i++) {
+ LogRecord record = LogRecord.newInstance(LogLevel.INFO, 0, i + " info", "grlgjlrmgr jglerj mgrjm gre pjkogremoiqp jgpo rejopigjrej,m", "grkgherjfezoprjgbpdofajhlbnb;k nfkfjgmjmsg", i, new String[0]);
+ s.write(record.toString() + '\n');
+ }
+ t1 = System.currentTimeMillis();
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
+ //pause(500);
+ t0 = System.currentTimeMillis();
+ for (i = 3 * MAX_0; i < 4 * MAX_0; i++) {
+ LogRecord record = LogRecord.newInstance(LogLevel.DEBUG, 0, i + " debug", "grmgjueroijiorehjnjodj j gn mbr,nhltrhjjdo jp joi jreio j", "gezoeteroiyerphehkzb,fgbd bcmsherkgheiusbcjkdvberb ", i, new String[0]);
+ s.write(record.toString() + '\n');
+ s.flush();
+ }
+ t1 = System.currentTimeMillis();
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
+ //pause(500);
+ t0 = System.currentTimeMillis();
+ for (i = 4 * MAX_0; i < 5 * MAX_0; i++) {
+ LogRecord record = LogRecord.newInstance(LogLevel.TRACE, 0, i + " trace", "ffgkdhvlsdknjk eriopgejo ipjiropj i io poi opijgr pe jupoieruj ga geigerihpi oeop erp ", "griofeioteogbbekjbnrjemk prejrlmekhgrehivbn rekhgrhi ", i, new String[0]);
+ s.write(record.toString() + '\n');
+ }
+ t1 = System.currentTimeMillis();
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
+ //pause(500);
+ t0 = System.currentTimeMillis();
+ for (i = 5 * MAX_0; i < 6 * MAX_0; i++) {
+ LogRecord record = LogRecord.newInstance(LogLevel.TRACE, 0, i + " user", "grekgrhze t e re klgre ge rgre gre gfer g rjyukj yujty reez ze fz", "gekfhezh zhrze hgerhglkrej ljbvkxdfn df,ekgrrnvkmn", i, new String[0]);
+ s.write(record.toString() + '\n');
+ s.flush();
+ }
+ t1 = System.currentTimeMillis();
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
+ } catch (OutOfMemoryError e) {
+ t1 = System.currentTimeMillis();
+ log.info("failed after | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
+ e.printStackTrace();
+ } finally {
+ if (s != null) {
+ s.flush();
+ s.close();
+ }
+ }
+ }
+
+ /**
+ * create a mock of logEvents
+ *
+ * @throws java.io.IOException todo
+ * @throws InterruptedException todo
+ */
+ public static void mockLogFile2() throws IOException, InterruptedException {
+ File f = new File(filename);
+ if (f.exists()) {
+ f.delete();
+ }
+ BufferedWriter s = new BufferedWriter(new FileWriter(f));
+ int MAX_0 = (int) (MEGA_STREAM_SIZE / 6);
+ int i = 0;
+ long t0, t00;
+ long t1;
+ totalPause = 0;
+ t00 = System.currentTimeMillis();
+ t0 = System.currentTimeMillis();
+ try {
+
+ for (i = 0; i < MAX_0; i++) {
+ LogRecord record = LogRecord.newInstance(LogLevel.FATAL, 0, i + "debug ", "ioreiovrio veuio vreupo xz xe opiu tep uxr u ", "xeoiujoiz xpo puoi rui hp", i, new String[0]);
+ s.write(record.toString() + '\n');
+ s.flush();
+ }
+
+ t1 = System.currentTimeMillis();
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
+ //pause(500);
+ t0 = System.currentTimeMillis();
+
+ for (i = MAX_0; i < 2 * MAX_0; i++) {
LogRecord record = LogRecord.newInstance(LogLevel.WARN, 0, i + " warn", "jkljfdjkl fdkjlkj lkjdlkfjl dfkljl dflkfdj lfdjlk fjdlkj fdl", "vmfof o rieipk?prj,ùnklvndfkljn gmlrtsoîjrmoig", i, new String[0]);
s.write(record.toString() + '\n');
}
t1 = System.currentTimeMillis();
- log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1-t0) + " | total " + i + " in " + StringUtil.convertTime( t1 - totalPause-t00));
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
//pause(500);
t0 = System.currentTimeMillis();
for (i = 2 * MAX_0; i < 3 * MAX_0; i++) {
@@ -76,7 +174,7 @@
s.write(record.toString() + '\n');
}
t1 = System.currentTimeMillis();
- log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1-t0) + " | total " + i + " in " + StringUtil.convertTime( t1 - totalPause-t00));
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
//pause(500);
t0 = System.currentTimeMillis();
for (i = 3 * MAX_0; i < 4 * MAX_0; i++) {
@@ -85,7 +183,7 @@
s.flush();
}
t1 = System.currentTimeMillis();
- log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1-t0) + " | total " + i + " in " + StringUtil.convertTime( t1 - totalPause-t00));
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
//pause(500);
t0 = System.currentTimeMillis();
for (i = 4 * MAX_0; i < 5 * MAX_0; i++) {
@@ -93,7 +191,7 @@
s.write(record.toString() + '\n');
}
t1 = System.currentTimeMillis();
- log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1-t0) + " | total " + i + " in " + StringUtil.convertTime( t1 - totalPause-t00));
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
//pause(500);
t0 = System.currentTimeMillis();
for (i = 5 * MAX_0; i < 6 * MAX_0; i++) {
@@ -102,10 +200,10 @@
s.flush();
}
t1 = System.currentTimeMillis();
- log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1-t0) + " | total " + i + " in " + StringUtil.convertTime( t1 - totalPause-t00));
+ log.debug("create next [" + MAX_0 + "] in " + StringUtil.convertTime(t1 - t0) + " | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
} catch (OutOfMemoryError e) {
t1 = System.currentTimeMillis();
- log.info("failed after | total " + i + " in " + StringUtil.convertTime( t1 - totalPause-t00));
+ log.info("failed after | total " + i + " in " + StringUtil.convertTime(t1 - totalPause - t00));
e.printStackTrace();
} finally {
if (s != null) {
@@ -122,7 +220,7 @@
IsisFish.init();
} catch (Exception e) {
throw new RuntimeException(e);
- }
+ }
}
/**
@@ -193,7 +291,7 @@
String fileName,
String methodName,
int lineNumber,
- String[] errors) {
+ String[] errors) throws UnsupportedEncodingException {
return new LogRecord(
level == null ? LogLevel.DEBUG.ordinal() : level.ordinal(),
timestamp,
@@ -211,11 +309,11 @@
String filename,
String methodName,
int lineNumber,
- String[] throwableStrRep) {
+ String[] throwableStrRep) throws UnsupportedEncodingException {
this.level = level;
this.timeStamp = timestamp;
//this.message = message;
- this.message = filename + ":" + lineNumber + " - " + methodName + " - " + message;
+ this.message = new String((filename + ":" + lineNumber + " - " + methodName + " - " + message).getBytes("utf-8"));
//this.filename = filename;
//this.methodName = methodName;
//this.lineNumber = lineNumber;
Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderTest.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderTest.java 2009-01-13 16:51:24 UTC (rev 1737)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderTest.java 2009-01-13 19:48:00 UTC (rev 1738)
@@ -1,5 +1,6 @@
package fr.ifremer.isisfish.logging.io;
+import fr.ifremer.TestUtils;
import fr.ifremer.isisfish.logging.TestUtil;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
@@ -20,6 +21,8 @@
protected static final Log log = LogFactory.getLog(LineReaderTest.class);
+ File testDir;
+
final static int[] sizes = new int[]{
10,
50,
@@ -38,19 +41,23 @@
protected void setUp() throws Exception {
super.setUp();
- new File("bench").mkdirs();
+
+ testDir = new File(TestUtils.getTargetdir(), "bench_" + System.nanoTime());
+ testDir.mkdirs();
+ System.out.println("benchdir " + testDir);
+
}
- protected void createMock(int i) throws IOException, InterruptedException {
+ protected static void createMock(File testDir, int i) throws IOException, InterruptedException {
TestUtil.MEGA_STREAM_SIZE = 6 * i;
- TestUtil.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + 6 * i + ".log";
- File file = new File(TestUtil.filename);
+ TestUtil.filename = new File(testDir, LineReaderTest.class.getSimpleName() + "_" + 6 * i + ".log").getAbsolutePath();
+ File file = new File(testDir, TestUtil.filename);
long t0 = System.nanoTime();
TestUtil.mockLogFile();
long t1;
t1 = System.nanoTime();
- log.info("create [" + TestUtil.MEGA_STREAM_SIZE + "] in " + StringUtil.convertTime(t1-t0) + " [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "]");
+ log.info("create [" + TestUtil.MEGA_STREAM_SIZE + "] in " + StringUtil.convertTime(t1 - t0) + " [file: " + file + ", length: " + StringUtil.convertMemory(file.length()) + "]");
System.gc();
}
@@ -58,7 +65,7 @@
public void estMakeMock() throws Exception {
for (int size : sizes) {
- createMock(size);
+ createMock(testDir, size);
}
}
@@ -110,8 +117,9 @@
private boolean showLog = false;
protected LineReader createReader(File f, String ext) throws IOException {
- return new LineReader(f, new FileOffsetReader(new File(f,ext)));
+ return new LineReader(f, new FileOffsetReader(new File(f, ext)));
}
+
protected void scanAllLines(int size) throws IOException {
TestUtil.MEGA_STREAM_SIZE = size;
TestUtil.filename = "bench/" + LineReaderTest.class.getSimpleName() + "_" + TestUtil.MEGA_STREAM_SIZE + ".log";
@@ -357,7 +365,7 @@
System.out.println("");
System.out.println("");
- LineReader reader2 = new LineReader(reader, new FileOffsetReader(new File(f,"offsets_debug_or_warn"))) {
+ LineReader reader2 = new LineReader(reader, new FileOffsetReader(new File(f, "offsets_debug_or_warn"))) {
public boolean match(String line) {
return line.contains("debug") || line.contains("warn");
}
@@ -384,7 +392,7 @@
System.out.println("");
System.out.println("");
- LineReader reader3 = new LineReader(reader, new FileOffsetReader(new File(f,"offsets_debug"))) {
+ LineReader reader3 = new LineReader(reader, new FileOffsetReader(new File(f, "offsets_debug"))) {
public boolean match(String line) {
return line.contains("debug");
}
Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderUtilTest.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderUtilTest.java 2009-01-13 16:51:24 UTC (rev 1737)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/logging/io/LineReaderUtilTest.java 2009-01-13 19:48:00 UTC (rev 1738)
@@ -1,7 +1,9 @@
package fr.ifremer.isisfish.logging.io;
+import fr.ifremer.TestUtils;
import fr.ifremer.isisfish.logging.LogLevel;
import fr.ifremer.isisfish.logging.LogLevelUtil;
+import fr.ifremer.isisfish.logging.TestUtil;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -18,6 +20,18 @@
protected static final Log log = LogFactory.getLog(LineReaderUtilTest.class);
+ static File testDir;
+
+ public static File getTestDir() {
+ if (testDir == null) {
+ testDir = new File(TestUtils.getTargetdir(), "bench_" + System.nanoTime());
+ if (!testDir.mkdirs()) {
+ throw new IllegalStateException("could not create directory " + testDir);
+ }
+ }
+ return testDir;
+ }
+
final static int[] sizes = new int[]{
10,
50,
@@ -37,15 +51,14 @@
protected void setUp() throws Exception {
super.setUp();
- new File("bench").mkdirs();
- String filename = "bench/LineReaderTest_30.log";
- f = new File(filename);
+ System.out.println("benchdir " + getTestDir());
+ String filename = "LineReaderTest_30.log";
+ f = new File(testDir, filename);
+
if (!f.exists()) {
- new LineReaderTest().createMock(5);
+ TestUtil.createMock(testDir, filename, 5);
}
-
-
}
@@ -54,14 +67,14 @@
long nbLines;
LineReader reader, reader2;
- reader = new LineReader(f, new FileOffsetReader(new File(f, "offsets")));
+ reader = new LineReader(f, new FileOffsetReader(new File(f.getParentFile(), "offsets")));
reader.getOffsetReader().deleteOffsetFile();
reader.open();
nbLines = reader.getNbLines();
assertEquals(30, nbLines);
log.info("found " + nbLines + " in reader " + reader);
- reader2 = new LineReaderUtil.LevelLineReader(reader, new FileOffsetReader(new File(reader.getFile(), "leveloffsets_" + LogLevel.DEBUG.mask())), LogLevel.DEBUG);
+ reader2 = new LineReaderUtil.LevelLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + LogLevel.DEBUG.mask())), LogLevel.FATAL);
reader2.getOffsetReader().deleteOffsetFile();
reader2.open();
nbLines = reader2.getNbLines();
@@ -69,13 +82,21 @@
assertEquals(5, nbLines);
reader2.close();
- reader2 = new LineReaderUtil.LevelLineReader(reader, new FileOffsetReader(new File(reader.getFile(), "leveloffsets_" + LogLevel.INFO.mask())), LogLevel.INFO);
+ reader2 = new LineReaderUtil.LevelLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + LogLevel.DEBUG.mask())), LogLevel.DEBUG);
reader2.getOffsetReader().deleteOffsetFile();
reader2.open();
nbLines = reader2.getNbLines();
log.info("found " + nbLines + " in reader " + reader2);
assertEquals(5, nbLines);
+ reader2.close();
+
+ reader2 = new LineReaderUtil.LevelLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + LogLevel.INFO.mask())), LogLevel.INFO);
reader2.getOffsetReader().deleteOffsetFile();
+ reader2.open();
+ nbLines = reader2.getNbLines();
+ log.info("found " + nbLines + " in reader " + reader2);
+ assertEquals(5, nbLines);
+ reader2.getOffsetReader().deleteOffsetFile();
reader2.close();
reader.getOffsetReader().deleteOffsetFile();
@@ -84,11 +105,11 @@
public void testLevelsReader() throws Exception {
- LineReader reader, reader2,reader3;
+ LineReader reader, reader2, reader3;
int levels;
long nbLines;
- reader = new LineReader(f, new FileOffsetReader(new File(f, "offsets")));
+ reader = new LineReader(f, new FileOffsetReader(new File(f.getParentFile(), "offsets")));
reader.getOffsetReader().deleteOffsetFile();
reader.open();
nbLines = reader.getNbLines();
@@ -96,7 +117,7 @@
log.info("found " + nbLines + " in reader " + reader);
levels = LogLevelUtil.createSet(LogLevel.DEBUG, LogLevel.INFO);
- reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile(), "leveloffsets_" + levels)), LogLevel.DEBUG, LogLevel.INFO);
+ reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.DEBUG, LogLevel.INFO);
reader2.getOffsetReader().deleteOffsetFile();
reader2.open();
nbLines = reader2.getNbLines();
@@ -106,7 +127,7 @@
reader2.close();
levels = LogLevelUtil.createSet(LogLevel.WARN, LogLevel.INFO);
- reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile(), "leveloffsets_" + levels)), LogLevel.INFO, LogLevel.WARN);
+ reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.INFO, LogLevel.WARN);
reader2.getOffsetReader().deleteOffsetFile();
assertTrue(reader2.getOffsetReader().needCreate());
reader2.open();
@@ -114,8 +135,8 @@
log.info("found " + nbLines + " in reader " + reader2);
assertEquals(10, nbLines);
- levels = LogLevelUtil.createSet( LogLevel.INFO);
- reader3 = new LineReaderUtil.LevelsLineReader(reader2, new FileOffsetReader(new File(reader.getFile(), "leveloffsets_" + levels)), LogLevel.INFO);
+ levels = LogLevelUtil.createSet(LogLevel.INFO);
+ reader3 = new LineReaderUtil.LevelsLineReader(reader2, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.INFO);
reader3.getOffsetReader().deleteOffsetFile();
assertTrue(reader3.getOffsetReader().needCreate());
reader3.open();
@@ -123,11 +144,11 @@
log.info("found " + nbLines + " in reader " + reader3);
assertEquals(5, nbLines);
- reader2.close();
+ reader2.close();
reader3.close();
levels = LogLevelUtil.createSet(LogLevel.INFO, LogLevel.WARN);
- reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile(), "leveloffsets_" + levels)), LogLevel.WARN, LogLevel.INFO);
+ reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.WARN, LogLevel.INFO);
assertFalse(reader2.getOffsetReader().needCreate());
reader2.open();
nbLines = reader2.getNbLines();
@@ -137,7 +158,7 @@
reader2.close();
levels = LogLevelUtil.createSet(LogLevel.DEBUG);
- reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile(), "leveloffsets_" + levels)), LogLevel.DEBUG);
+ reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.DEBUG);
assertFalse(reader2.getOffsetReader().needCreate());
reader2.open();
nbLines = reader2.getNbLines();
@@ -146,7 +167,7 @@
reader2.close();
levels = LogLevelUtil.createSet(LogLevel.DEBUG, LogLevel.DEBUG);
- reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile(), "leveloffsets_" + levels)), LogLevel.DEBUG, LogLevel.DEBUG);
+ reader2 = new LineReaderUtil.LevelsLineReader(reader, new FileOffsetReader(new File(reader.getFile().getParentFile(), "leveloffsets_" + levels)), LogLevel.DEBUG, LogLevel.DEBUG);
assertFalse(reader2.getOffsetReader().needCreate());
reader2.open();
nbLines = reader2.getNbLines();
@@ -165,7 +186,7 @@
LineReader reader, reader2;
long nbLines;
- reader = new LineReader(f, new FileOffsetReader(new File(f, "offsets")));
+ reader = new LineReader(f, new FileOffsetReader(new File(f.getParentFile(), "offsets")));
reader.getOffsetReader().deleteOffsetFile();
reader.open();
nbLines = reader.getNbLines();
@@ -191,5 +212,5 @@
reader.getOffsetReader().deleteOffsetFile();
reader.close();
}
-
+
}
\ No newline at end of file
Modified: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationHelperTest.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationHelperTest.java 2009-01-13 16:51:24 UTC (rev 1737)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationHelperTest.java 2009-01-13 19:48:00 UTC (rev 1738)
@@ -31,42 +31,40 @@
package fr.ifremer.isisfish.simulator;
-import java.io.File;
-import java.util.Enumeration;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.math.matrix.DoubleBigVector;
-import org.codelutin.math.matrix.MatrixFactory;
-import org.codelutin.topia.TopiaContext;
-
+import fr.ifremer.TestUtils;
import fr.ifremer.isisfish.IsisFish;
import fr.ifremer.isisfish.datastore.ResultStorage;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.entities.Result;
import fr.ifremer.isisfish.types.Date;
-
import junit.framework.TestCase;
import junit.framework.TestFailure;
import junit.framework.TestResult;
import junit.framework.TestSuite;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.math.matrix.DoubleBigVector;
+import org.codelutin.math.matrix.MatrixFactory;
+import org.codelutin.topia.TopiaContext;
+import java.io.File;
+import java.util.Enumeration;
+import java.util.List;
-/**
- * @author poussin
- *
- */
+/** @author poussin */
+
public class SimulationHelperTest extends TestCase {
private static final Log log = LogFactory.getLog(SimulationHelperTest.class);
-
- final static private String [] SIMULATION_ZIP_FILE = new String[]{
- "src/test/fr/ifremer/isisfish/simulator/SimulationTest.zip",
- // put here other zip simulation test
- };
-
+
+ final static private String[] SIMULATION_ZIP_FILE = new String[]{
+ //TC - 20090113 : remove the asrc to src when the zip file will be in correct db version, otherwise there is a ui asking to migrate
+ // or just desactivate the migration service ?
+ "asrc" + File.separator + "test" + File.separator + "java" + File.separator + "fr" + File.separator + "ifremer" + File.separator + "isisfish" + File.separator + "simulator" + File.separator + "SimulationTest.zip",
+ // put here other zip simulation test
+ };
+
// public void testVerifResult() throws Exception {
// try {
// IsisConfig.load();
@@ -115,18 +113,19 @@
// }
// }
-/*
-10;20;30;40;50;60;70;80;90;
-100;200;300;400;500;600;700;800;900;
-1000;2000;3000;4000;5000;6000;7000;8000;9000;
-10000;20000;30000;40000;50000;60000;70000;80000;90000;
-100000;200000;300000;400000;500000;600000;700000;800000;900000;
-1000000;2000000;3000000;4000000;5000000;6000000;7000000;8000000;9000000;
-10000000;20000000;30000000;40000000;50000000;60000000;70000000;80000000;90000000;
-100000000;200000000;300000000;400000000;500000000;600000000;700000000;800000000;900000000;
-1000000000;2000000000;3000000000;4000000000;5000000000;6000000000;7000000000;8000000000;9000000000;
-10000000000;20000000000;30000000000;40000000000;50000000000;60000000000;70000000000;80000000000;90000000000;
-*/
+ /*
+ 10;20;30;40;50;60;70;80;90;
+ 100;200;300;400;500;600;700;800;900;
+ 1000;2000;3000;4000;5000;6000;7000;8000;9000;
+ 10000;20000;30000;40000;50000;60000;70000;80000;90000;
+ 100000;200000;300000;400000;500000;600000;700000;800000;900000;
+ 1000000;2000000;3000000;4000000;5000000;6000000;7000000;8000000;9000000;
+ 10000000;20000000;30000000;40000000;50000000;60000000;70000000;80000000;90000000;
+ 100000000;200000000;300000000;400000000;500000000;600000000;700000000;800000000;900000000;
+ 1000000000;2000000000;3000000000;4000000000;5000000000;6000000000;7000000000;8000000000;9000000000;
+ 10000000000;20000000000;30000000000;40000000000;50000000000;60000000000;70000000000;80000000000;90000000000;
+ */
+
public void testSimulate() throws Exception {
try {
// par defaut on utilise des doubles pour les matrices
@@ -135,36 +134,36 @@
for (String zipName : SIMULATION_ZIP_FILE) {
// recuperation du fichier zip de la simulation de test
- File zip = new File(zipName);
+ File zip = new File(TestUtils.getBasedir(), zipName);
// import de cette simulation
String name = "simulation-test-" + System.currentTimeMillis();
SimulationStorage simRef = SimulationStorage.importAndRenameZip(zip, name + "-ref");
// import de la simulation avec un autre nom
- SimulationStorage sim = SimulationStorage.importAndRenameZip(zip, name);
-
+ SimulationStorage sim = SimulationStorage.importAndRenameZip(zip, name);
+
try {
// suppression des resultats de cette simulation
TopiaContext tx = sim.getStorage().beginTransaction();
tx.execute("DELETE from " + Result.class.getName());
tx.commitTransaction();
-
+
// lancement de la simulation
// FIXME a remplacer avec SimulationService
// SimulationHelper.simulate(null, sim);
-
+
// verification qu'on retrouve les memes resulats pour les deux simulations
ResultStorage resultRef = simRef.getResultStorage();
ResultStorage result = sim.getResultStorage();
-
+
List<String> resultNames = resultRef.getResultName();
assertEquals(resultNames, result.getResultName());
-
+
Date lastDate = resultRef.getLastDate();
log.info("Check result ...");
- for (Date date=new Date(0); date.before(lastDate); date=date.next()) {
+ for (Date date = new Date(0); date.before(lastDate); date = date.next()) {
for (String resultName : resultNames) {
log.debug("Check result " + date + " " + resultName);
assertEquals("Date " + date.getDate() + " result " + resultName,
@@ -172,7 +171,7 @@
result.getMatrix(date, resultName));
}
}
-
+
} finally {
// fermeture des bases
simRef.getStorage().closeContext();
@@ -188,22 +187,22 @@
throw eee;
}
}
-
+
public static void main(String[] args) {
TestSuite suite = new TestSuite(SimulationHelperTest.class);
TestResult result = new TestResult();
suite.run(result);
if (result.wasSuccessful()) {
System.out.println("Test Ok");
- } else {
+ } else {
System.out.println("Test Faild");
System.out.println("Failures");
- for (Enumeration e=result.failures(); e.hasMoreElements();) {
+ for (Enumeration e = result.failures(); e.hasMoreElements();) {
System.out.println(e.nextElement().toString());
}
System.out.println("Errors");
- for (Enumeration e=result.errors(); e.hasMoreElements();) {
- TestFailure eee = (TestFailure)e.nextElement();
+ for (Enumeration e = result.errors(); e.hasMoreElements();) {
+ TestFailure eee = (TestFailure) e.nextElement();
System.out.println(eee.toString());
eee.thrownException().printStackTrace();
}
1
0
r1737 - in isis-fish/trunk: . src/test/java/fr/ifremer/isisfish/ui
by tchemit@users.labs.libre-entreprise.org 13 Jan '09
by tchemit@users.labs.libre-entreprise.org 13 Jan '09
13 Jan '09
Author: tchemit
Date: 2009-01-13 16:51:24 +0000 (Tue, 13 Jan 2009)
New Revision: 1737
Removed:
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/TestJaxx.java
Modified:
isis-fish/trunk/changelog.txt
isis-fish/trunk/pom.xml
Log:
passage en lutinproject 3.3 (+ suppression d'un test Jaxx)
Modified: isis-fish/trunk/changelog.txt
===================================================================
--- isis-fish/trunk/changelog.txt 2009-01-13 16:44:36 UTC (rev 1736)
+++ isis-fish/trunk/changelog.txt 2009-01-13 16:51:24 UTC (rev 1737)
@@ -1,6 +1,6 @@
isis-fish (3.2.0.x) xxx
- * switch to lutinproject 3.2
+ * switch to lutinproject 3.3
* switch to topia-service 1.0.1
* switch to topia-persistence 2.1.1
* remove tools.jar (now isis need JDK !!!)
Modified: isis-fish/trunk/pom.xml
===================================================================
--- isis-fish/trunk/pom.xml 2009-01-13 16:44:36 UTC (rev 1736)
+++ isis-fish/trunk/pom.xml 2009-01-13 16:51:24 UTC (rev 1737)
@@ -11,7 +11,7 @@
<parent>
<groupId>org.codelutin</groupId>
<artifactId>lutinproject</artifactId>
- <version>3.2</version>
+ <version>3.3</version>
</parent>
<groupId>ifremer</groupId>
@@ -73,13 +73,6 @@
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>org.codelutin.jaxx</groupId>
- <artifactId>jaxx-compiler-api</artifactId>
- <version>${jaxx.version}</version>
- <scope>test</scope>
- </dependency>
-
<!--Commons-->
<dependency>
<groupId>commons-jxpath</groupId>
@@ -342,6 +335,10 @@
<!-- for the moment skip tests -->
<maven.test.skip>true</maven.test.skip>
+ <!-- FIXE should at leaste be this !-->
+ <!-- Ignore failure test for now -->
+ <!--maven.test.testFailureIgnore>true</maven.test.testFailureIgnore-->
+
<!-- jnlp -->
<keystorepath>../../../CodeLutinKeystore</keystorepath>
<keystorealias>CodeLutin</keystorealias>
@@ -567,7 +564,7 @@
<execution>
<phase>verify</phase>
<goals>
- <goal>attached</goal>
+ <goal>inline</goal>
</goals>
</execution>
</executions>
Deleted: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/TestJaxx.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/TestJaxx.java 2009-01-13 16:44:36 UTC (rev 1736)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/ui/TestJaxx.java 2009-01-13 16:51:24 UTC (rev 1737)
@@ -1,38 +0,0 @@
-package fr.ifremer.isisfish.ui;
-
-import jaxx.reflect.ClassDescriptor;
-import jaxx.reflect.JavaFileParser;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.URL;
-
-/** @author chemit */
-public class TestJaxx {
-
- @Test
- public void testParseEntity() throws Exception {
- URL javaSource = new File("target/generated-sources/java/fr/ifremer/isisfish/entities/Cell.java").toURI().toURL();
-
- InputStream in = javaSource.openStream();
- Reader reader = new InputStreamReader(in, "utf-8");
- ClassDescriptor result = JavaFileParser.parseJavaFile(javaSource.toString(), reader, getClass().getClassLoader());
- reader.close();
- Assert.assertNotNull(result);
- }
-
- @Test
- public void testParseEntityImpl() throws Exception {
- URL javaSource = new File("src/main/java/fr/ifremer/isisfish/entities/CellImpl.java").toURI().toURL();
-
- InputStream in = javaSource.openStream();
- Reader reader = new InputStreamReader(in, "utf-8");
- ClassDescriptor result = JavaFileParser.parseJavaFile(javaSource.toString(), reader, getClass().getClassLoader());
- reader.close();
- Assert.assertNotNull(result);
- }
-}
1
0
r1736 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher
by chatellier@users.labs.libre-entreprise.org 13 Jan '09
by chatellier@users.labs.libre-entreprise.org 13 Jan '09
13 Jan '09
Author: chatellier
Date: 2009-01-13 16:44:36 +0000 (Tue, 13 Jan 2009)
New Revision: 1736
Modified:
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTableModel.java
Log:
Reduce very verbose log level
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTableModel.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTableModel.java 2009-01-13 13:45:32 UTC (rev 1735)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationServiceTableModel.java 2009-01-13 16:44:36 UTC (rev 1736)
@@ -210,8 +210,8 @@
Object result = "";
- if(log.isDebugEnabled()) {
- log.debug("Update table model : " +
+ if(log.isTraceEnabled()) {
+ log.trace("Update table model : " +
"id = " + control.getId() + ", " +
"control.getProgress() = " + control.getProgress() + ", " +
"control.getProgressMax() = " + control.getProgressMax() + ", "+
1
0
r1735 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator
by chatellier@users.labs.libre-entreprise.org 13 Jan '09
by chatellier@users.labs.libre-entreprise.org 13 Jan '09
13 Jan '09
Author: chatellier
Date: 2009-01-13 13:45:32 +0000 (Tue, 13 Jan 2009)
New Revision: 1735
Modified:
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx
Log:
Fix unsaved strategies list problem
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2009-01-13 13:33:49 UTC (rev 1734)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2009-01-13 13:45:32 UTC (rev 1735)
@@ -70,7 +70,6 @@
@Override
public void simulationStop(SimulationService simService, SimulationJob job) {
- System.out.println("refresh !!!");
fieldSimulParamsSelect.setModel(getSimulParamsSelectModel());
}
@@ -178,6 +177,7 @@
i++;
}
listSimulParamsStrategies.setSelectedIndices(indexs);
+ strategySelected();
}
}
protected void setListSimulParamsPopulationsItems(){
1
0
Author: chatellier
Date: 2009-01-13 13:33:49 +0000 (Tue, 13 Jan 2009)
New Revision: 1734
Modified:
isis-fish/trunk/pom.xml
Log:
Les test d?\195?\169pendent explicitement du compilateur jaxx.
Le plugin eclipse:eclipse ne les trouve pas.
Modified: isis-fish/trunk/pom.xml
===================================================================
--- isis-fish/trunk/pom.xml 2009-01-13 13:17:54 UTC (rev 1733)
+++ isis-fish/trunk/pom.xml 2009-01-13 13:33:49 UTC (rev 1734)
@@ -11,7 +11,7 @@
<parent>
<groupId>org.codelutin</groupId>
<artifactId>lutinproject</artifactId>
- <version>3.3</version>
+ <version>3.2</version>
</parent>
<groupId>ifremer</groupId>
@@ -73,6 +73,13 @@
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.codelutin.jaxx</groupId>
+ <artifactId>jaxx-compiler-api</artifactId>
+ <version>${jaxx.version}</version>
+ <scope>test</scope>
+ </dependency>
+
<!--Commons-->
<dependency>
<groupId>commons-jxpath</groupId>
1
0
Author: chatellier
Date: 2009-01-13 13:17:54 +0000 (Tue, 13 Jan 2009)
New Revision: 1733
Modified:
isis-fish/trunk/pom.xml
Log:
Update libs
Modified: isis-fish/trunk/pom.xml
===================================================================
--- isis-fish/trunk/pom.xml 2009-01-12 18:05:58 UTC (rev 1732)
+++ isis-fish/trunk/pom.xml 2009-01-13 13:17:54 UTC (rev 1733)
@@ -11,7 +11,7 @@
<parent>
<groupId>org.codelutin</groupId>
<artifactId>lutinproject</artifactId>
- <version>3.2</version>
+ <version>3.3</version>
</parent>
<groupId>ifremer</groupId>
@@ -26,7 +26,7 @@
<dependency>
<groupId>org.codelutin</groupId>
<artifactId>lutinutil</artifactId>
- <version>1.0.1</version>
+ <version>1.0.2</version>
<scope>compile</scope>
</dependency>
@@ -325,7 +325,7 @@
<jaxx.version>1.1-SNAPSHOT</jaxx.version>
<generator.version>0.63</generator.version>
<topia.version>2.1.1</topia.version>
- <lutinwidget.version>0.12-SNAPSHOT</lutinwidget.version>
+ <lutinwidget.version>0.12</lutinwidget.version>
<lutinmatrix.version>1.2-SNAPSHOT</lutinmatrix.version>
<openmap.version>4.6.4</openmap.version>
@@ -550,7 +550,7 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
- <version>2.2-beta-2</version>
+ <version>2.2-beta-3</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/bin.xml</descriptor>
1
0
r1732 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input
by sletellier@users.labs.libre-entreprise.org 12 Jan '09
by sletellier@users.labs.libre-entreprise.org 12 Jan '09
12 Jan '09
Author: sletellier
Date: 2009-01-12 18:05:58 +0000 (Mon, 12 Jan 2009)
New Revision: 1732
Modified:
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputOneEquationUI.jaxx
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationBasicsUI.jaxx
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationGroupUI.jaxx
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/WizardGroupCreationUI.jaxx
Log:
WizardGroupCreation work
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputOneEquationUI.jaxx
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputOneEquationUI.jaxx 2009-01-12 18:05:16 UTC (rev 1731)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputOneEquationUI.jaxx 2009-01-12 18:05:58 UTC (rev 1732)
@@ -86,6 +86,7 @@
if (selected != null){
editor.setText(selected.getContent());
}
+ f = selected;
}
protected Formule getFormule(){
Formule result = null;
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationBasicsUI.jaxx
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationBasicsUI.jaxx 2009-01-12 18:05:16 UTC (rev 1731)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationBasicsUI.jaxx 2009-01-12 18:05:58 UTC (rev 1732)
@@ -92,7 +92,8 @@
protected void createClasses(){
JFrame wizardFrame = new JFrame();
wizardFrame.setLayout(new BorderLayout());
- WizardGroupCreationUI wizard = new WizardGroupCreationUI(getContextValue(InputAction.class), this);
+ WizardGroupCreationUI wizard = new WizardGroupCreationUI(this);
+ wizard.init(this);
wizardFrame.add(wizard, BorderLayout.CENTER);
wizardFrame.setTitle(_("isisfish.wizardGroupCreation.title"));
wizardFrame.setVisible(true);
@@ -134,7 +135,6 @@
}
protected void create(){
Species species = getAction().getSpeciesByTopiaId(getVerifier().getIsisContext(), getVerifier().getCurrentNode().getParent().getNavigationPath());
- System.out.println(species);
TopiaEntity topia = getContextValue(InputAction.class).createPopulation(getVerifier().getIsisContext(), species);
getParentContainer(InputUI.class).setTreeModel();
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationGroupUI.jaxx
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationGroupUI.jaxx 2009-01-12 18:05:16 UTC (rev 1731)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/PopulationGroupUI.jaxx 2009-01-12 18:05:58 UTC (rev 1732)
@@ -76,6 +76,7 @@
Population population = (Population)getVerifier().getEntity(Population.class);
setBean((PopulationImpl) population);
jaxx.runtime.swing.Utils.fillComboBox(fieldPopulationGroupPopulationGroup,getBean().getPopulationGroup(), null);
+ getVerifier().addCurrentEntity(getPopulationGroup());
}
]]>
</script>
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/WizardGroupCreationUI.jaxx
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/WizardGroupCreationUI.jaxx 2009-01-12 18:05:16 UTC (rev 1731)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/WizardGroupCreationUI.jaxx 2009-01-12 18:05:58 UTC (rev 1732)
@@ -56,10 +56,8 @@
protected double step = 1;
protected PopulationBasicsUI popBasic;
-// setCard("endInputGroupLength");
- public WizardGroupCreationUI(InputAction action, PopulationBasicsUI p){
-
- setContextValue(action);
+
+ public void init(PopulationBasicsUI p){
popBasic = p;
}
@@ -334,7 +332,7 @@
}
protected void cancel(){
- getParentContainer(JFrame.class).dispose();
+ getParentContainer(JFrame.class).dispose();
}
protected void refreshChoice(){
setInputType(beginGroupLengthTypeInput.isSelected());
1
0
12 Jan '09
Author: sletellier
Date: 2009-01-12 18:05:16 +0000 (Mon, 12 Jan 2009)
New Revision: 1731
Modified:
isis-fish/trunk/src/main/xmi/isis-fish.zargo
Log:
Correction de l'unicit?\195?\169 entre les populations et les maturityGroupes
Modified: isis-fish/trunk/src/main/xmi/isis-fish.zargo
===================================================================
(Binary files differ)
1
0
Author: sletellier
Date: 2009-01-12 16:38:00 +0000 (Mon, 12 Jan 2009)
New Revision: 1730
Modified:
isis-fish/trunk/pom.xml
Log:
JAXX 1.1-SNAPSHOT
Modified: isis-fish/trunk/pom.xml
===================================================================
--- isis-fish/trunk/pom.xml 2009-01-12 15:01:10 UTC (rev 1729)
+++ isis-fish/trunk/pom.xml 2009-01-12 16:38:00 UTC (rev 1730)
@@ -60,14 +60,14 @@
<!--Jaxx-->
<dependency>
- <groupId>org.codelutin</groupId>
+ <groupId>org.codelutin.jaxx</groupId>
<artifactId>jaxx-runtime-swing</artifactId>
<version>${jaxx.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.codelutin</groupId>
+ <groupId>org.codelutin.jaxx</groupId>
<artifactId>jaxx-runtime-validator</artifactId>
<version>${jaxx.version}</version>
<scope>compile</scope>
@@ -322,7 +322,7 @@
<labs.project>isis-fish</labs.project>
<!-- Custom version -->
- <jaxx.version>1.0-SNAPSHOT</jaxx.version>
+ <jaxx.version>1.1-SNAPSHOT</jaxx.version>
<generator.version>0.63</generator.version>
<topia.version>2.1.1</topia.version>
<lutinwidget.version>0.12-SNAPSHOT</lutinwidget.version>
@@ -387,7 +387,7 @@
</plugin>
<plugin>
- <groupId>org.codelutin</groupId>
+ <groupId>org.codelutin.jaxx</groupId>
<artifactId>maven-jaxx-plugin</artifactId>
<version>${jaxx.version}</version>
<executions>
1
0