diff --git a/pom.xml b/pom.xml
index c038e26..71835cf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,11 +54,6 @@
4.12.1
test
-
- org.testifyproject.mock
- mockito
- 1.0.4
-
\ No newline at end of file
diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java
index ba94468..9a3efab 100644
--- a/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java
+++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum1/GrosseZahl.java
@@ -68,7 +68,6 @@ public class GrosseZahl {
if(this.equals(b)) {
return new GrosseZahl(0);
} else if(this.less(b)) {
- System.out.println("sub() kann keine negativen Werte zurückgeben.");
return new GrosseZahl(0);
}
GrosseZahl rueckgabe = new GrosseZahl(this.toString());
diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum4/KlausurenServer.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum4/KlausurenServer.java
index 10c46e1..8583a2a 100644
--- a/src/main/java/de/joethei/hs/java2/praktikum/praktikum4/KlausurenServer.java
+++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum4/KlausurenServer.java
@@ -2,22 +2,22 @@ package de.joethei.hs.java2.praktikum.praktikum4;
import java.io.IOException;
import java.net.ServerSocket;
-import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.*;
public class KlausurenServer {
private ConcurrentMap> data = new ConcurrentHashMap<>();
private static ExecutorService executorService = Executors.newCachedThreadPool();
+ private static ServerSocket serverSocket;
+
private static Map commands = new HashMap<>();
+ private boolean running;
+
public KlausurenServer(int port) {
commands.put("test", ((writer, args) -> writer.write("Hallo Welt")));
commands.put("put", (writer, args) -> {
@@ -65,18 +65,26 @@ public class KlausurenServer {
});
commands.put("stop", ((writer, args) -> {
writer.write("1");
- executorService.shutdown();
- System.exit(0);
+ running = false;
}));
-
+ running = true;
Runnable runnable = () -> {
try {
- ServerSocket serverSocket = new ServerSocket(port);
+ serverSocket = new ServerSocket(port);
System.out.println("waiting for clients");
- while (true) {
- Socket clientSocket = serverSocket.accept();
- executorService.submit(new ClientRunnable(clientSocket));
+ while (running) {
+ executorService.submit(new ClientRunnable(serverSocket.accept()));
}
+ executorService.shutdown();
+ try {
+ executorService.awaitTermination(10, TimeUnit.MINUTES);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ serverSocket.close();
+ System.out.println("server shutdown");
+ Thread.currentThread().interrupt();
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/main/resources/praktikum4/data b/src/main/resources/praktikum4/data
new file mode 100644
index 0000000..e69de29
diff --git a/src/test/java/de/joethei/hs/java2/tests/KlausurenServerTest.java b/src/test/java/de/joethei/hs/java2/tests/KlausurenServerTest.java
index 48d43ae..638ca94 100644
--- a/src/test/java/de/joethei/hs/java2/tests/KlausurenServerTest.java
+++ b/src/test/java/de/joethei/hs/java2/tests/KlausurenServerTest.java
@@ -13,9 +13,11 @@ import static org.junit.Assert.assertEquals;
@RunWith(OrderedRunner.class)
public class KlausurenServerTest {
+ private static KlausurenServer server;
+
@BeforeClass
public static void before() {
- new KlausurenServer(6767);
+ server = new KlausurenServer(6767);
}
@Test
@@ -29,6 +31,7 @@ public class KlausurenServerTest {
public void put() {
assertEquals("1", sendRequest("put max@maier 6, 5"));
assertEquals("1 5, 6", sendRequest("put max@maier 7,8"));
+ assertEquals("0", sendRequest("put max@maier"));
}
@Test(timeout = 60L)
@@ -49,8 +52,20 @@ public class KlausurenServerTest {
public void del() {
assertEquals("0", sendRequest("del max@maier baum"));
assertEquals("1 5, 6, 7, 8", sendRequest("del max@maier"));
+ assertEquals("0", sendRequest("get max@maier"));
}
+ /*
+ @Test(timeout = 700L)
+ @Order(order = 6)
+ public void saved() throws InterruptedException {
+ assertEquals("1", sendRequest("stop"));
+ Thread.sleep(500L);
+ server = new KlausurenServer(6767);
+ assertEquals("1 [5, 6, 7, 8]", sendRequest("getall"));
+ }
+ */
+
private String sendRequest(String command) {
try {
Socket socket = new Socket("localhost", 6767);