avancement
This commit is contained in:
parent
72ebb50107
commit
89735ebea9
14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
|
@ -4,6 +4,20 @@
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Launch BasicTestCB",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "linda.test.BasicTestCB",
|
||||||
|
"projectName": "Projet PDR"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Launch testserver",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "linda.test.testserver",
|
||||||
|
"projectName": "Projet PDR"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "java",
|
"type": "java",
|
||||||
"name": "Launch Main",
|
"name": "Launch Main",
|
||||||
|
|
81
docs/rapport.md
Normal file
81
docs/rapport.md
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
# Rapport de projet de données réparties
|
||||||
|
|
||||||
|
Fainsin Laurent - 2SN M2 \
|
||||||
|
Guillotin Damien - 2SN M2
|
||||||
|
|
||||||
|
## Consignes
|
||||||
|
|
||||||
|
Rendus : Vous devez rendre le 16/1/2022:
|
||||||
|
- un petit rapport présentant l’architecture, les algorithmes des opérations essentielles, une explication claire des points délicats et de leur résolution, et un mot sur les exemples originaux développés ;
|
||||||
|
- le code complet, y compris le plan de test et les tests que vous avez développés.
|
||||||
|
Attention :
|
||||||
|
- le code des exemples fournis doit compiler et s’exécuter correctement sans que vous y touchiez le moindre caractère (sauf pour changer l’utilisation du linda centralisé / linda mono-serveur). Ces tests valident votre respect de l’API. Ils ne sont cependant absolument pas exhaustifs et vous devez développer vos propres tests.
|
||||||
|
- vos tests et votre plan de test seront évalués.
|
||||||
|
|
||||||
|
## Organisation du projet
|
||||||
|
|
||||||
|
Le projet est écrit en Java (17) et ses dépendances sont gérées par gradle. Les fonctionnalités développées sont regroupées dans des packages et leur détails seront explicités plus bas. Pour effectuer des tests nous utilisation la librairie JUnit5 et pour vérifier que nos tests sont efficaces nous utilisons Jacoco (pour obtenir le code-coverage).
|
||||||
|
|
||||||
|
Pour lancer les test JUnit5:
|
||||||
|
```bash
|
||||||
|
gradle tasks test
|
||||||
|
```
|
||||||
|
|
||||||
|
Pour lancer Jacoco:
|
||||||
|
```bash
|
||||||
|
gradle tasks jacocoTestReport
|
||||||
|
```
|
||||||
|
|
||||||
|
Pour ouvrir le rapport Jacoco:
|
||||||
|
```bash
|
||||||
|
firefox build/reports/jacoco/test/html/index.html
|
||||||
|
```
|
||||||
|
|
||||||
|
## Organisation des packages
|
||||||
|
|
||||||
|
### linda
|
||||||
|
|
||||||
|
Ce package contient les interfaces et les classes nécéssaires à l'ensemble du projet. Nous n'y avons pas touchées, celles-ci étant fournis par le sujet.
|
||||||
|
|
||||||
|
### linda.shm
|
||||||
|
|
||||||
|
Ce package contient l'implémentation `CentralizedLinda` de l'interface `Linda`. Ainsi, ont été écrites les primitives: \
|
||||||
|
`write`, `take`, `tryTake`, `takeAll`, `read`, `tryRead`, `readAll`, `eventRegister`.
|
||||||
|
|
||||||
|
`CentralizedLinda` permet la création de l'espace partagé de données typées Linda centralisé sur la machine sur laquelle le programme est lancé.
|
||||||
|
|
||||||
|
De nombreux tests ont été effectués sur cette implémentation via `linda.test.CentralizedLindaTests`. Le code coverage atteint presque 100%.
|
||||||
|
|
||||||
|
### linda.server
|
||||||
|
|
||||||
|
Pour partager l'implémentation précédente entre plusieurs machines/processus, nous pouvons l'enregistrer dans un registre RMI et créer les interfaces associées pour permettre aux clients/servers de communiquer.
|
||||||
|
|
||||||
|
Ainsi nous avons créé l'interface `LindaRemote`, reprenant les méthodes de `Linda`.
|
||||||
|
De même nous avons créé la classe `LindaServer` implémentant `LindaRemote` et dont le but est de publier dans un registre RMI une instance `CentralizedLinda`. `LindaClient` vient simplement chercher une instance `Linda` dans le registre RMI et passe l'ensemble de ses actions à cette instance.
|
||||||
|
|
||||||
|
Pour les tests nous avons simplement repris ceux de `CentralizedLinda` mais nous les avons adaptés pour que ceux-ci fonctionne avec RMI.
|
||||||
|
|
||||||
|
### linda.eratosthene
|
||||||
|
|
||||||
|
Cette application est constituée d'un serveur responsable de distribuer les tuples à tester, et de clients responsables d'effectuer des calculs sur ces tuples.
|
||||||
|
Ainsi `Server` instancie un `LindaServer` de la partie précédente et initialise le tuple-space avec des tuples formés d'un entier (l'entier dont ont veut tester la primalité) et de deux strings qui indiquent l'état de test de cet entier.
|
||||||
|
Chaque `Client` se contente simplement de se connecter au serveur et de vérifier la primalité d'un tuple, une fois son calcul terminé, il place le résultat dans le tuple-space. Cette dynamique persiste tant qu'il existe encore un entier non testé dans le tuple-space.
|
||||||
|
|
||||||
|
Pour les tests nous comparons simplement les entiers retournés avec des entiers dont nous sommes sûrs qu'ils soient premiers.
|
||||||
|
|
||||||
|
### linda.search.basic
|
||||||
|
|
||||||
|
Cette application fonctionne directement grâce au code `Server` et `Client` écrit précédemment. Ainsi, comme demandé, nous avons ajouté les fonctionnalités :
|
||||||
|
|
||||||
|
- avoir plusieurs activités de recherche (qui traitent concurremment la même requête).
|
||||||
|
- avoir plusieurs activités manager (qui déposent plusieurs requêtes).
|
||||||
|
- l’utilisation avec le linda serveur : le(s) manager(s) et le(s) chercheurs sont chacun un client distinct.
|
||||||
|
- le démarrage dynamique et arbitraire de chercheurs : avant le dépôt ou alors que des chercheurs ont déjà commencé. La terminaison du manager devient un point délicat.
|
||||||
|
- l’arrêt arbitraire de chercheurs ; le manager doit réaliser qu’il n’y en a plus aucun.
|
||||||
|
- le retrait de la recherche par le manager après un certain délai (par exemple 5 secondes) alors que les chercheurs n’ont pas fini. Dans ce cas, il est important de laisser le système dans un état propre, tel que les chercheurs puissent commencer une nouvelle recherche si un nouveau manager en dépose une.
|
||||||
|
|
||||||
|
Pour les tests nous lançons simplements plusieurs intances de `Manager` et `Searcher` et nous comparons avec des résultats connus.
|
||||||
|
|
||||||
|
### linda.whiteboard
|
||||||
|
|
||||||
|
Cette application fonctionne nativement.
|
|
@ -3,8 +3,10 @@ package linda.server;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import java.rmi.server.UnicastRemoteObject;
|
import java.rmi.server.UnicastRemoteObject;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.rmi.*;
|
import java.rmi.*;
|
||||||
import java.rmi.registry.LocateRegistry;
|
import java.rmi.registry.LocateRegistry;
|
||||||
|
import java.rmi.registry.Registry;
|
||||||
|
|
||||||
import linda.Callback;
|
import linda.Callback;
|
||||||
import linda.Linda;
|
import linda.Linda;
|
||||||
|
@ -17,44 +19,54 @@ import linda.shm.CentralizedLinda;
|
||||||
public class LindaServer extends UnicastRemoteObject implements LindaRemote {
|
public class LindaServer extends UnicastRemoteObject implements LindaRemote {
|
||||||
|
|
||||||
Linda lindaInstance;
|
Linda lindaInstance;
|
||||||
|
Registry registry;
|
||||||
|
LindaServer ls;
|
||||||
|
|
||||||
public LindaServer() throws RemoteException {
|
public LindaServer() throws RemoteException {
|
||||||
this.lindaInstance = new CentralizedLinda();
|
this.lindaInstance = new CentralizedLinda();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public LindaServer(int port) throws RemoteException {
|
||||||
Integer port = 4000;
|
|
||||||
|
|
||||||
if (args.length == 2) {
|
|
||||||
port = Integer.parseInt(args[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
String url = "rmi://localhost:" + port + "/linda";
|
String url = "rmi://localhost:" + port + "/linda";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LindaServer ls = new LindaServer();
|
this.ls = new LindaServer();
|
||||||
LocateRegistry.createRegistry(port);
|
this.registry = LocateRegistry.createRegistry(port);
|
||||||
Naming.rebind(url, ls);
|
Naming.rebind(url, this.ls);
|
||||||
System.out.println("L'instance Linda a été publiée sur le registre (" + url + ") !");
|
System.out.println("L'instance Linda a été publiée sur le registre (" + url + ") !");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(Tuple t) {
|
public static void main(String... args) throws RemoteException {
|
||||||
System.out.println("received write request;" + t);
|
Integer port = 4000;
|
||||||
|
if (args.length == 2)
|
||||||
|
port = Integer.parseInt(args[1]);
|
||||||
|
|
||||||
|
new LindaServer(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() throws AccessException, RemoteException, NotBoundException {
|
||||||
|
this.registry.unbind("linda");
|
||||||
|
UnicastRemoteObject.unexportObject(this.ls, true);
|
||||||
|
UnicastRemoteObject.unexportObject(this.registry, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(Tuple t) throws RemoteException {
|
||||||
|
System.out.println("received write request: " + t);
|
||||||
lindaInstance.write(t);
|
lindaInstance.write(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tuple take(Tuple template) throws RemoteException {
|
public Tuple take(Tuple template) throws RemoteException {
|
||||||
Tuple res = lindaInstance.take(template);
|
Tuple res = lindaInstance.take(template);
|
||||||
System.out.println("received take request, with template: " + template + "\nreturning:" + res);
|
System.out.println("received take request, with template: " + template + "\nreturning: " + res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tuple read(Tuple template) throws RemoteException {
|
public Tuple read(Tuple template) throws RemoteException {
|
||||||
Tuple res = lindaInstance.read(template);
|
Tuple res = lindaInstance.read(template);
|
||||||
System.out.println("received read request, with template: " + template + "\nreturning:" + res);
|
System.out.println("received read request, with template: " + template + "\nreturning: " + res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,4 +94,5 @@ public class LindaServer extends UnicastRemoteObject implements LindaRemote {
|
||||||
public void debug(String prefix) throws RemoteException {
|
public void debug(String prefix) throws RemoteException {
|
||||||
lindaInstance.debug(prefix);
|
lindaInstance.debug(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,56 +0,0 @@
|
||||||
package linda.test;
|
|
||||||
|
|
||||||
import linda.*;
|
|
||||||
|
|
||||||
public class BasicTest1 {
|
|
||||||
|
|
||||||
public static void main(String[] a) {
|
|
||||||
|
|
||||||
final Linda linda = new linda.shm.CentralizedLinda();
|
|
||||||
// final Linda linda = new linda.server.LindaClient("//localhost:4000/aaa");
|
|
||||||
|
|
||||||
new Thread() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(2);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Tuple motif = new Tuple(Integer.class, String.class);
|
|
||||||
Tuple res = linda.take(motif);
|
|
||||||
System.out.println("(1) Resultat:" + res);
|
|
||||||
linda.debug("(1)");
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
|
|
||||||
new Thread() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
Tuple t1 = new Tuple(4, 5);
|
|
||||||
System.out.println("(2) write: " + t1);
|
|
||||||
linda.write(t1);
|
|
||||||
|
|
||||||
Tuple t11 = new Tuple(4, 5);
|
|
||||||
System.out.println("(2) write: " + t11);
|
|
||||||
linda.write(t11);
|
|
||||||
|
|
||||||
Tuple t2 = new Tuple("hello", 15);
|
|
||||||
System.out.println("(2) write: " + t2);
|
|
||||||
linda.write(t2);
|
|
||||||
|
|
||||||
Tuple t3 = new Tuple(4, "foo");
|
|
||||||
System.out.println("(2) write: " + t3);
|
|
||||||
linda.write(t3);
|
|
||||||
|
|
||||||
linda.debug("(2)");
|
|
||||||
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
package linda.test;
|
|
||||||
|
|
||||||
import linda.*;
|
|
||||||
|
|
||||||
public class BasicTest2 {
|
|
||||||
|
|
||||||
public static void main(String[] a) {
|
|
||||||
final Linda linda = new linda.shm.CentralizedLinda();
|
|
||||||
// final Linda linda = new linda.server.LindaClient("//localhost:4000/MonServeur");
|
|
||||||
|
|
||||||
for (int i = 1; i <= 3; i++) {
|
|
||||||
final int j = i;
|
|
||||||
new Thread() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(2);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Tuple motif = new Tuple(Integer.class, String.class);
|
|
||||||
Tuple res = linda.read(motif);
|
|
||||||
System.out.println("("+j+") Resultat:" + res);
|
|
||||||
linda.debug("("+j+")");
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
new Thread() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(2000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
Tuple t1 = new Tuple(4, 5);
|
|
||||||
System.out.println("(0) write: " + t1);
|
|
||||||
linda.write(t1);
|
|
||||||
|
|
||||||
Tuple t2 = new Tuple("hello", 15);
|
|
||||||
System.out.println("(0) write: " + t2);
|
|
||||||
linda.write(t2);
|
|
||||||
|
|
||||||
linda.debug("(0)");
|
|
||||||
|
|
||||||
Tuple t3 = new Tuple(4, "foo");
|
|
||||||
System.out.println("(0) write: " + t3);
|
|
||||||
linda.write(t3);
|
|
||||||
|
|
||||||
linda.debug("(0)");
|
|
||||||
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -23,8 +23,8 @@ public class BasicTestCB {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] a) {
|
public static void main(String[] a) {
|
||||||
linda = new linda.shm.CentralizedLinda();
|
// linda = new linda.shm.CentralizedLinda();
|
||||||
// linda = new linda.server.LindaClient("//localhost:4000/MonServeur");
|
linda = new linda.server.LindaClient("rmi://localhost:4000/linda");
|
||||||
|
|
||||||
cbmotif = new Tuple(Integer.class, String.class);
|
cbmotif = new Tuple(Integer.class, String.class);
|
||||||
|
|
||||||
|
|
421
src/test/java/linda/test/ClientServerTests.java
Normal file
421
src/test/java/linda/test/ClientServerTests.java
Normal file
|
@ -0,0 +1,421 @@
|
||||||
|
package linda.test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.rmi.AccessException;
|
||||||
|
import java.rmi.NotBoundException;
|
||||||
|
import java.rmi.RemoteException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import linda.Callback;
|
||||||
|
import linda.Linda;
|
||||||
|
import linda.Tuple;
|
||||||
|
import linda.Linda.eventMode;
|
||||||
|
import linda.Linda.eventTiming;
|
||||||
|
import linda.server.LindaClient;
|
||||||
|
import linda.server.LindaServer;
|
||||||
|
|
||||||
|
public class ClientServerTests {
|
||||||
|
|
||||||
|
LindaServer ls;
|
||||||
|
Linda linda;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() throws RemoteException, InterruptedException {
|
||||||
|
ls = new LindaServer(4000);
|
||||||
|
Thread.sleep(100);
|
||||||
|
linda = new LindaClient("rmi://localhost:4000/linda");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void cleanup() throws AccessException, RemoteException, NotBoundException, InterruptedException {
|
||||||
|
ls.stop();
|
||||||
|
Thread.sleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("read related tests")
|
||||||
|
class ReadTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testTryRead() {
|
||||||
|
Tuple tuple_write, tuple_template, tuple_read;
|
||||||
|
|
||||||
|
tuple_template = new Tuple(0);
|
||||||
|
tuple_read = linda.tryRead(tuple_template);
|
||||||
|
assertEquals(tuple_read, null);
|
||||||
|
|
||||||
|
tuple_template = new Tuple(Integer.class);
|
||||||
|
tuple_read = linda.tryRead(tuple_template);
|
||||||
|
assertEquals(tuple_read, null);
|
||||||
|
|
||||||
|
tuple_write = new Tuple(0);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
|
||||||
|
tuple_template = new Tuple(0);
|
||||||
|
tuple_read = linda.tryRead(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
|
||||||
|
tuple_template = new Tuple(Integer.class);
|
||||||
|
tuple_read = linda.tryRead(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testRead() {
|
||||||
|
Tuple tuple_write, tuple_template, tuple_read;
|
||||||
|
|
||||||
|
tuple_write = new Tuple(0);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
|
||||||
|
tuple_template = new Tuple(0);
|
||||||
|
tuple_read = linda.read(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
|
||||||
|
tuple_template = new Tuple(Integer.class);
|
||||||
|
tuple_read = linda.read(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testEmptyRead() {
|
||||||
|
Thread mainRunner = new Thread(() -> {
|
||||||
|
Tuple tuple_template;
|
||||||
|
tuple_template = new Tuple(Integer.class);
|
||||||
|
linda.read(tuple_template);
|
||||||
|
});
|
||||||
|
|
||||||
|
mainRunner.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
assertEquals(Thread.State.WAITING, mainRunner.getState());
|
||||||
|
mainRunner.interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testWaitingRead() throws InterruptedException {
|
||||||
|
Tuple tuple_write = new Tuple(0);
|
||||||
|
|
||||||
|
Thread runnerExact = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(Integer.class);
|
||||||
|
Tuple tuple_read = linda.read(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
});
|
||||||
|
runnerExact.start();
|
||||||
|
|
||||||
|
Thread runnerType = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(Integer.class);
|
||||||
|
Tuple tuple_read = linda.read(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
});
|
||||||
|
runnerType.start();
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testReadAll() {
|
||||||
|
Tuple tuple_template;
|
||||||
|
Collection<Tuple> tuples_write, tuples_read, tuples_expected;
|
||||||
|
|
||||||
|
tuples_write = new ArrayList<Tuple>();
|
||||||
|
tuples_expected = new ArrayList<Tuple>();
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple(0));
|
||||||
|
tuples_expected.add(new Tuple(0));
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple(1));
|
||||||
|
tuples_expected.add(new Tuple(1));
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple(2));
|
||||||
|
tuples_expected.add(new Tuple(2));
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple("3"));
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple("4"));
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple(5));
|
||||||
|
tuples_expected.add(new Tuple(5));
|
||||||
|
|
||||||
|
for (Tuple tuple : tuples_write) {
|
||||||
|
linda.write(tuple);
|
||||||
|
}
|
||||||
|
|
||||||
|
tuple_template = new Tuple(Integer.class);
|
||||||
|
tuples_read = linda.readAll(tuple_template);
|
||||||
|
assertEquals(tuples_expected, tuples_read);
|
||||||
|
|
||||||
|
assertNotEquals(linda.tryRead(tuple_template), null);
|
||||||
|
assertNotEquals(linda.tryRead(new Tuple(String.class)), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("Take related tests")
|
||||||
|
class TakeTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testTryTake() {
|
||||||
|
Tuple tuple_write, tuple_template, tuple_read;
|
||||||
|
|
||||||
|
tuple_template = new Tuple(0);
|
||||||
|
tuple_read = linda.tryTake(tuple_template);
|
||||||
|
assertEquals(tuple_read, null);
|
||||||
|
|
||||||
|
tuple_template = new Tuple(Integer.class);
|
||||||
|
tuple_read = linda.tryTake(tuple_template);
|
||||||
|
assertEquals(tuple_read, null);
|
||||||
|
|
||||||
|
tuple_write = new Tuple(0);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
|
||||||
|
tuple_template = new Tuple(0);
|
||||||
|
tuple_read = linda.tryTake(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
|
||||||
|
tuple_template = new Tuple(Integer.class);
|
||||||
|
tuple_read = linda.tryTake(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testWaitingTake() throws InterruptedException {
|
||||||
|
Tuple tuple_write = new Tuple(0);
|
||||||
|
|
||||||
|
Thread runnerExact = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(Integer.class);
|
||||||
|
Tuple tuple_read = linda.take(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
});
|
||||||
|
runnerExact.start();
|
||||||
|
|
||||||
|
Thread runnerType = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(Integer.class);
|
||||||
|
Tuple tuple_read = linda.take(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
});
|
||||||
|
runnerType.start();
|
||||||
|
|
||||||
|
Thread.sleep(500);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
Thread.sleep(500);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testEmptyTake() {
|
||||||
|
Thread mainRunner = new Thread(() -> {
|
||||||
|
Tuple tuple_template;
|
||||||
|
tuple_template = new Tuple(Integer.class);
|
||||||
|
linda.take(tuple_template);
|
||||||
|
});
|
||||||
|
|
||||||
|
mainRunner.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
assertEquals(Thread.State.WAITING, mainRunner.getState());
|
||||||
|
mainRunner.interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testTake() {
|
||||||
|
Tuple tuple_write, tuple_template, tuple_read;
|
||||||
|
|
||||||
|
tuple_write = new Tuple(0);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
|
||||||
|
tuple_template = new Tuple(0);
|
||||||
|
tuple_read = linda.take(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
|
||||||
|
tuple_template = new Tuple(Integer.class);
|
||||||
|
tuple_read = linda.take(tuple_template);
|
||||||
|
assertEquals(tuple_read, tuple_write);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testTakeAll() {
|
||||||
|
Tuple tuple_template;
|
||||||
|
Collection<Tuple> tuples_write, tuples_read, tuples_expected;
|
||||||
|
|
||||||
|
tuples_write = new ArrayList<Tuple>();
|
||||||
|
tuples_expected = new ArrayList<Tuple>();
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple(0));
|
||||||
|
tuples_expected.add(new Tuple(0));
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple(1));
|
||||||
|
tuples_expected.add(new Tuple(1));
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple(2));
|
||||||
|
tuples_expected.add(new Tuple(2));
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple("3"));
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple("4"));
|
||||||
|
|
||||||
|
tuples_write.add(new Tuple(5));
|
||||||
|
tuples_expected.add(new Tuple(5));
|
||||||
|
|
||||||
|
for (Tuple tuple : tuples_write) {
|
||||||
|
linda.write(tuple);
|
||||||
|
}
|
||||||
|
|
||||||
|
tuple_template = new Tuple(Integer.class);
|
||||||
|
tuples_read = linda.takeAll(tuple_template);
|
||||||
|
assertEquals(tuples_expected, tuples_read);
|
||||||
|
|
||||||
|
assertEquals(linda.tryTake(tuple_template), null);
|
||||||
|
assertNotEquals(linda.tryTake(new Tuple(String.class)), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("eventRegister related tests")
|
||||||
|
class EventRegisterTests {
|
||||||
|
|
||||||
|
final Tuple tuple_write = new Tuple(0);
|
||||||
|
|
||||||
|
Callback assertCallback = new Callback() {
|
||||||
|
@Override
|
||||||
|
public void call(Tuple t) {
|
||||||
|
assertEquals(t, tuple_write);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void IMMEDIATE_READ_test() throws InterruptedException {
|
||||||
|
Thread runnerExact = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(0);
|
||||||
|
linda.eventRegister(
|
||||||
|
eventMode.READ,
|
||||||
|
eventTiming.IMMEDIATE,
|
||||||
|
tuple_template,
|
||||||
|
assertCallback);
|
||||||
|
});
|
||||||
|
runnerExact.start();
|
||||||
|
|
||||||
|
Thread runnerType = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(Integer.class);
|
||||||
|
linda.eventRegister(
|
||||||
|
eventMode.READ,
|
||||||
|
eventTiming.IMMEDIATE,
|
||||||
|
tuple_template,
|
||||||
|
assertCallback);
|
||||||
|
});
|
||||||
|
runnerType.start();
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void IMMEDIATE_TAKE_test() throws InterruptedException {
|
||||||
|
linda.write(new Tuple("999"));
|
||||||
|
|
||||||
|
Thread runnerExact = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(0);
|
||||||
|
linda.eventRegister(
|
||||||
|
eventMode.TAKE,
|
||||||
|
eventTiming.IMMEDIATE,
|
||||||
|
tuple_template,
|
||||||
|
assertCallback);
|
||||||
|
});
|
||||||
|
runnerExact.start();
|
||||||
|
|
||||||
|
Thread runnerType = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(Integer.class);
|
||||||
|
linda.eventRegister(
|
||||||
|
eventMode.TAKE,
|
||||||
|
eventTiming.IMMEDIATE,
|
||||||
|
tuple_template,
|
||||||
|
assertCallback);
|
||||||
|
});
|
||||||
|
runnerType.start();
|
||||||
|
|
||||||
|
Thread.sleep(500);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
Thread.sleep(500);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void FUTURE_READ_test() throws InterruptedException {
|
||||||
|
linda.write(new Tuple(999));
|
||||||
|
linda.write(new Tuple("999"));
|
||||||
|
|
||||||
|
Thread runnerExact = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(0);
|
||||||
|
linda.eventRegister(
|
||||||
|
eventMode.READ,
|
||||||
|
eventTiming.FUTURE,
|
||||||
|
tuple_template,
|
||||||
|
assertCallback);
|
||||||
|
});
|
||||||
|
runnerExact.start();
|
||||||
|
|
||||||
|
Thread runnerType = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(Integer.class);
|
||||||
|
linda.eventRegister(
|
||||||
|
eventMode.READ,
|
||||||
|
eventTiming.FUTURE,
|
||||||
|
tuple_template,
|
||||||
|
assertCallback);
|
||||||
|
});
|
||||||
|
runnerType.start();
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void FUTURE_TAKE_test() throws InterruptedException {
|
||||||
|
linda.write(new Tuple(999));
|
||||||
|
linda.write(new Tuple("999"));
|
||||||
|
|
||||||
|
Thread runnerExact = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(0);
|
||||||
|
linda.eventRegister(
|
||||||
|
eventMode.TAKE,
|
||||||
|
eventTiming.FUTURE,
|
||||||
|
tuple_template,
|
||||||
|
assertCallback);
|
||||||
|
});
|
||||||
|
runnerExact.start();
|
||||||
|
|
||||||
|
Thread runnerType = new Thread(() -> {
|
||||||
|
Tuple tuple_template = new Tuple(Integer.class);
|
||||||
|
linda.eventRegister(
|
||||||
|
eventMode.TAKE,
|
||||||
|
eventTiming.FUTURE,
|
||||||
|
tuple_template,
|
||||||
|
assertCallback);
|
||||||
|
});
|
||||||
|
runnerType.start();
|
||||||
|
|
||||||
|
Thread.sleep(500);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
Thread.sleep(500);
|
||||||
|
linda.write(tuple_write);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ import java.util.ArrayList;
|
||||||
import linda.Callback;
|
import linda.Callback;
|
||||||
import linda.Tuple;
|
import linda.Tuple;
|
||||||
|
|
||||||
public class ClientTest implements Callback, Serializable {
|
public class REPL implements Callback, Serializable {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
@ -51,18 +51,18 @@ public class ClientTest implements Callback, Serializable {
|
||||||
System.out.println("Il faut indiquer la commande et un tuple ! Ex : > r 1 S\n");
|
System.out.println("Il faut indiquer la commande et un tuple ! Ex : > r 1 S\n");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Serializable[] objets = new Serializable[args.length-1];
|
Serializable[] objets = new Serializable[args.length - 1];
|
||||||
|
|
||||||
for (int i = 1; i < args.length; i++) {
|
for (int i = 1; i < args.length; i++) {
|
||||||
if (args[i].equals("I")) {
|
if (args[i].equals("I")) {
|
||||||
objets[i-1] = Integer.class;
|
objets[i - 1] = Integer.class;
|
||||||
} else if (args[i].equals("S")) {
|
} else if (args[i].equals("S")) {
|
||||||
objets[i-1] = String.class;
|
objets[i - 1] = String.class;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
objets[i-1] = Integer.parseInt(args[i]);
|
objets[i - 1] = Integer.parseInt(args[i]);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
objets[i-1] = args[i];
|
objets[i - 1] = args[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue