Skip to content
Snippets Groups Projects
Commit f305af98 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

test: junit for haas demonstrating existing bug #1115

parent a65ed33c
No related branches found
No related tags found
No related merge requests found
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>kozusznik</groupId>
<artifactId>haas-experiment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>haas-experiment</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cz.it4i.fiji</groupId>
<artifactId>haas-java-client</artifactId>
<version>0.0.7-SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
package kozusznik.haas_experiment;
import java.io.InterruptedIOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.haas_java_client.HaaSClient;
import cz.it4i.fiji.haas_java_client.HaaSFileTransfer;
import cz.it4i.fiji.haas_java_client.JobInfo;
import cz.it4i.fiji.haas_java_client.JobState;
import cz.it4i.fiji.haas_java_client.UploadingFileData;
public class Routines {
public static final Logger log = LoggerFactory.getLogger(kozusznik.haas_experiment.Routines.class);
public static long startBDS(HaaSClient client) throws InterruptedException {
long jobId = 429;/*client.createJob(new
JobSettingsBuilder().jobName("TestOutRedirect").templateId(4l)
.walltimeLimit(600).clusterNodeType(7l).build(), Collections.emptyList());
*/
JobInfo info = client.obtainJobInfo(jobId);
log.info("JobId :" + jobId + ", state - " + info.getState());
if (info.getState() != JobState.Running) {
try (HaaSFileTransfer transfer = client.startFileTransfer(jobId)) {
transfer.upload(new UploadingFileData("run-bds"));
} catch (InterruptedIOException e) {
log.error(e.getMessage(), e);
}
client.submitJob(jobId);
}
JobState state;
while((state = client.obtainJobInfo(jobId).getState()) != JobState.Running) {
log.info("state - " + state);
Thread.sleep(3000);
}
return jobId;
}
}
package kozusznik.haas_experiment;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import javax.xml.rpc.ServiceException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.haas_java_client.HaaSClient;
import cz.it4i.fiji.haas_java_client.HaaSClientSettings;
import cz.it4i.fiji.haas_java_client.HaaSDataTransfer;
import cz.it4i.fiji.haas_java_client.SettingsProvider;
/**
* Demonstrate failure reported in https://vpsupport.vsb.cz:8002/redmine/issues/1115
*/
class TestConnectionCloseCase {
public static final Logger log = LoggerFactory.getLogger(kozusznik.haas_experiment.TestConnectionCloseCase.class);
private final static String MSG = //
"GET /data/ HTTP/1.1\r\n" + //
"Host: localhost:8080\r\n" + //
"User-Agent: curl/7.47.0\r\n" + //
"Accept: */*\r\n" + //
"\r\n";;
private static HaaSClient client;
private static long jobID;
@BeforeAll
static void setUpBeforeClass() throws Exception {
HaaSClientSettings settings = SettingsProvider.getSettings("OPEN-12-20",
TestingConstants.CONFIGURATION_FILE_NAME);
client = new HaaSClient(settings);
jobID = Routines.startBDS(client);
}
@BeforeEach
void setUp() throws Exception {
}
@Test
void test$1Scenarion() {
try (HaaSDataTransfer dataTransfer = client.startDataTransfer(jobID, 0, 8081)) {
log.info("#1 scenario - #1 request");
dataTransfer.write(MSG.getBytes());
log.info("#1 scenario - response of #1 request:");
logResponse(dataTransfer.read());
dataTransfer.closeConnection();
log.info("#1 scenario - #2 request");
dataTransfer.write(MSG.getBytes());
log.info("#1 scenario - response of #2 request:");
byte[] response;
logResponse(response = dataTransfer.read());
assertNotNull(response);
dataTransfer.closeConnection();
} catch (IOException | ServiceException e) {
fail(e.getMessage(), e);
}
}
@Test
void test$2Scenario() throws Exception {
log.info("#2 scenario");
try(HaaSDataTransfer dataTransfer = client.startDataTransfer(jobID, 0, 8081)) {
log.info("#2 scenario - #1 request");
dataTransfer.write(MSG.getBytes());
log.info("#2 scenario - response of #1 request:");
logResponse(dataTransfer.read());
dataTransfer.closeConnection();
log.info("try to read before write:");
//MAY BLOCK FOR READ
CompletableFuture<?> f = CompletableFuture.runAsync(() -> logResponse(dataTransfer.read()));
Thread.sleep(3000);
assertFalse(f.isDone());
dataTransfer.closeConnection();
}
}
private static void logResponse(byte[] data) {
if(data == null) {
log.warn("Closed connection from middleware");
} else {
log.info(new String(data));
}
}
}
package kozusznik.haas_experiment;
public interface TestingConstants {
String CONFIGURATION_FILE_NAME = "configuration.properties";
}
USER_NAME=testuser
PASSWORD=e4b437415d
EMAIL=jan.kozusznik@vsb.cz
PHONE=999111000
\ No newline at end of file
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
org.slf4j.simpleLogger.defaultLogLevel=debug
# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.cz.it4i.fiji.haas_java_client.MidlewareTunnel=debug
# Set to true if you want the current date and time to be included in output messages.
# Default is false, and will output the number of milliseconds elapsed since startup.
#org.slf4j.simpleLogger.showDateTime=false
# The date and time format to be used in the output messages.
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
# If the format is not specified or is invalid, the default format is used.
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
# Set to true if you want to output the current thread name.
# Defaults to true.
#org.slf4j.simpleLogger.showThreadName=true
# Set to true if you want the Logger instance name to be included in output messages.
# Defaults to true.
#org.slf4j.simpleLogger.showLogName=true
# Set to true if you want the last component of the name to be included in output messages.
# Defaults to false.
#org.slf4j.simpleLogger.showShortLogName=false
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment