8000 Added the tck-main file (#358) · chakra-coder/rsocket-java@a0bc944 · GitHub
[go: up one dir, main page]

Skip to content

Commit a0bc944

Browse files
junaidkhalidyschimke
authored andcommitted
Added the tck-main file (rsocket#358)
* Added a main file which I removed a while back. This is required for running cross implementation compatibility tests. Removing this file did not break anything becuase Cross implemetation tests were using an older version of rsocket-java Following changes are temporary RSocket client = createClient(this.uri); this.createClient = () -> client; This part will be rewritten when I will the support for multiple clients. Each test will be run by a new client object(s).
1 parent f12155c commit a0bc944

File tree

5 files changed

+240
-99
lines changed

5 files changed

+240
-99
lines changed

rsocket-tck-drivers/src/main/java/io/rsocket/tckdrivers/client/JavaClientDriver.java

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@
1717

1818
import io.rsocket.Payload;
1919
import io.rsocket.RSocket;
20+
import io.rsocket.RSocketFactory;
2021
import io.rsocket.tckdrivers.common.ConsoleUtils;
2122
import io.rsocket.tckdrivers.common.EchoSubscription;
2223
import io.rsocket.tckdrivers.common.MySubscriber;
2324
import io.rsocket.tckdrivers.common.ParseChannel;
2425
import io.rsocket.tckdrivers.common.ParseChannelThread;
2526
import io.rsocket.tckdrivers.common.ParseMarble;
27+
import io.rsocket.tckdrivers.common.TckIndividualTest;
2628
import io.rsocket.tckdrivers.common.Tuple;
29+
import io.rsocket.transport.ClientTransport;
30+
import io.rsoc 8000 ket.uri.UriTransportRegistry;
2731
import io.rsocket.util.PayloadImpl;
32+
import java.io.BufferedReader;
33+
import java.io.File;
2834
import java.io.FileNotFoundException;
35+
import java.io.FileReader;
2936
import java.util.ArrayList;
3037
import java.util.HashMap;
3138
import java.util.Iterator;
@@ -49,15 +56,26 @@ public class JavaClientDriver {
4956
private final Map<String, MySubscriber<Payload>> payloadSubscribers;
5057
private final Map<String, MySubscriber<Void>> fnfSubscribers;
5158
private final Map<String, String> idToType;
52-
private final Supplier<RSocket> createClient;
59+
private Supplier<RSocket> createClient;
60+
private final String uri;
5361
private final String AGENT = "[CLIENT]";
5462
private ConsoleUtils consoleUtils = new ConsoleUtils(AGENT);
5563

56-
public JavaClientDriver(Supplier<RSocket> createClient) throws FileNotFoundException {
64+
public JavaClientDriver(String uri) throws FileNotFoundException {
5765
this.payloadSubscribers = new HashMap<>();
5866
this.fnfSubscribers = new HashMap<>();
5967
this.idToType = new HashMap<>();
60-
this.createClient = createClient;
68+
this.uri = uri;
69+
70+
// creating a client object to run the test
71+
try {
72+
73+
RSocket client = createClient(this.uri);
74+
this.createClient = () -> client;
75+
76+
} catch (Exception e) {
77+
e.printStackTrace();
78+
}
6179
}
6280

6381
public enum TestResult {
@@ -66,6 +84,15 @@ public enum TestResult {
6684
CHANNEL
6785
}
6886

87+
/**
88+
* A function that creates a RSocket on a new TCP connection.
89+
*
90+
* @return a RSocket
91+
*/
92+
public RSocket createClient(String uri) {
93+
return RSocketFactory.connect().transport(UriTransportRegistry.clientForUri(uri)).start().block();
94+
}
95+
6996
/**
7097
* Parses through the commands for each test, and calls handlers that execute the commands.
7198
*
@@ -493,4 +520,48 @@ public void request(long n) {
493520
if (m > 0) pm.request(m);
494521
}
495522
}
523+
524+
/**
525+
* A function that parses the file and extract the individual tests
526+
*
527+
* @param file The file to read as input.
528+
* @return a list of TckIndividualTest.
529+
*/
530+
public static List<TckIndividualTest> extractTests(File file) throws Exception {
531+
532+
BufferedReader reader = new BufferedReader(new FileReader(file));
533+
List<TckIndividualTest> tests = new ArrayList<>();
534+
List<String> test = new ArrayList<>();
535+
String line = reader.readLine();
536+
String testFile = file.getName().replaceFirst(TckIndividualTest.clientPrefix, "");
537+
538+
//Parsing the input client file to read all the tests
539+
while (line != null) {
540+
switch (line) {
541+
case "!":
542+
String name = "";
543+
if (test.size() > 1) {
544+
name = test.get(0).split("%%")[1];
545+
}
546+
547+
TckIndividualTest tckTest = new TckIndividualTest(name, test, testFile);
548+
tests.add(tckTest);
549+
test = new ArrayList<>();
550+
break;
551+
default:
552+
test.add(line);
553+
break;
554+
}
555+
line = reader.readLine();
556+
}
557+
558+
if (test.size() > 0) {
559+
String name = "";
560+
name = test.get(0).split("%%")[1];
561+
TckIndividualTest tckTest = new TckIndividualTest(name, test, testFile);
562+
tests.add(tckTest);
563+
tests = tests.subList(1, tests.size()); // remove the first list, which is empty
564+
}
565+
return tests;
566+
}
496567
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2016 Facebook, Inc.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package io.rsocket.tckdrivers.common;
15+
16+
import java.util.List;
17+
18+
public class TckIndividualTest {
19+
public String name; // Test name
20+
public List<String> test; // test instructions/commands
21+
public String testFile; // Test belong to this file. File name is without client/server prefix
22+
public static final String serverPrefix = "server";
23+
public static final String clientPrefix = "client";
24+
25+
public TckIndividualTest(String name, List<String> test, String testFile) {
26+
this.name = name;
27+
this.test = test;
28+
this.testFile = testFile;
29+
}
30+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright 2016 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.rsocket.tckdrivers.main;
18+
19+
import io.airlift.airline.Command;
20+
import io.airlift.airline.Option;
21+
import io.airlift.airline.SingleCommand;
22+
import io.rsocket.tckdrivers.client.JavaClientDriver;
23+
import io.rsocket.tckdrivers.common.TckIndividualTest;
24+
import io.rsocket.tckdrivers.server.JavaTCPServer;
25+
import java.io.*;
26+
import java.util.ArrayList;
27+
import java.util.Arrays;
28+
import java.util.List;
29+
30+
/** This class is used to run both the server and the client, depending on the options given */
31+
@Command(
32+
name = "rsocket-driver",
33+
description = "This runs the client and servers that use the driver"
34+
)
35+
public class Main {
36+
37+
@Option(name = "--server", description = "set if you want to run the server")
38+
public static boolean server;
39+
40+
@Option(name = "--client", description = "set if you want to run the client")
41+
public static boolean client;
42+
43+
@Option(name = "--host", description = "The host to connect to for the client")
44+
public static String host;
45+
46+
@Option(name = "--port", description = "The port")
47+
public static int port;
48+
49+
@Option(
50+
name = "--file",
51+
description =
52+
"The script file to parse, make sure to give the client and server the " + "correct files"
53+
)
54+
public static String file;
55+
56+
@Option(
57+
name = "--tests",
58+
description =
59+
"For the client only, optional argument to list out the tests you"
60+
+ " want to run, should be comma separated names"
61+
)
62+
public static String tests;
63+
64+
/**
65+
* A function that parses the test file, and run each test
66+
*
67+
* @param realfile file to read. If null, it reads clienttest.txt
68+
* @param host client connects with this host
69+
* @param port client connects on this port
70+
* @testsList list of tests to run
71+
*/
72+
public static void runTests(String realfile, String host, int port, List<String> testsList)
73+
throws Exception {
74+
// we pass in our reactive socket here to the test suite
75+
String filepath = "rsocket-tck-drivers/src/test/resources/clienttest.txt";
76+
if (realfile != null) filepath = realfile;
77+
78+
List<List<String>> tests = new ArrayList<>();
79+
List<String> test = new ArrayList<>();
80+
File file = new File(filepath);
81+
for (TckIndividualTest t : JavaClientDriver.extractTests(file)) {
82+
83+
if (testsList.size() > 0) {
84+
if (!testsList.contains(t.name)) {
85+
continue;
86+
}
87+
}
88+
try {
89+
JavaClientDriver jd = new JavaClientDriver("tcp://" + host + ":" + port + "/rs");
90+
jd.runTest(t.test.subList(1, t.test.size()), t.name);
91+
} catch (Exception e) {
92+
e.printStackTrace();
93+
}
94+
}
95+
}
96+
97+
public static void main(String[] args) {
98+
SingleCommand<Main> cmd = SingleCommand.singleCommand(Main.class);
99+
cmd.parse(args);
100+
boolean passed = true;
101+
102+
if (server) {
103+
new JavaTCPServer().run(file, port);
104+
} else if (client) {
105+
try {
106+
if (tests != null) {
107+
runTests(file, host, port, Arrays.asList(tests.split(",")));
108+
} else {
109+
runTests(file, host, port, new ArrayList<>());
110+
}
111+
} catch (Exception e) {
112+
e.printStackTrace();
113+
}
114+
}
115+
}
116+
}

rsocket-tck-drivers/src/main/java/io/rsocket/tckdrivers/server/JavaServerDriver.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.io.BufferedReader;
3737
import java.io.FileReader;
3838
import java.io.IOException;
39-
import java.nio.charset.StandardCharsets;
4039
import java.util.ArrayList;
4140
import java.util.HashMap;
4241
import java.util.HashSet;

0 commit comments

Comments
 (0)
0