Skip to content

Commit 87b60c5

Browse files
initial import
0 parents  commit 87b60c5

14 files changed

+901
-0
lines changed

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.DS_Store
2+
.gradle
3+
.idea
4+
.classpath
5+
.project
6+
.settings
7+
.yardoc
8+
.yardopts
9+
bin
10+
build
11+
target
12+
out
13+
*.iml
14+
*.ipr
15+
*.iws
16+
test-output
17+
Scratch.java
18+
ScratchTest.java
19+
test-results
20+
test-tmp
21+
*.class
22+
src/gen
23+
src/test/java/io/vertx/codegen/**
24+
src/test/java/com/acme/**
25+
src/test/scala/io/vertx/scala/codegen/**
26+
src/test/scala/com/acme/**
27+
src/test/asciidoc

LICENSE-2.0.txt

+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
2+
Apache License
3+
Version 2.0, January 2004
4+
http://www.apache.org/licenses/
5+
6+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7+
8+
1. Definitions.
9+
10+
"License" shall mean the terms and conditions for use, reproduction,
11+
and distribution as defined by Sections 1 through 9 of this document.
12+
13+
"Licensor" shall mean the copyright owner or entity authorized by
14+
the copyright owner that is granting the License.
15+
16+
"Legal Entity" shall mean the union of the acting entity and all
17+
other entities that control, are controlled by, or are under common
18+
control with that entity. For the purposes of this definition,
19+
"control" means (i) the power, direct or indirect, to cause the
20+
direction or management of such entity, whether by contract or
21+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
22+
outstanding shares, or (iii) beneficial ownership of such entity.
23+
24+
"You" (or "Your") shall mean an individual or Legal Entity
25+
exercising permissions granted by this License.
26+
27+
"Source" form shall mean the preferred form for making modifications,
28+
including but not limited to software source code, documentation
29+
source, and configuration files.
30+
31+
"Object" form shall mean any form resulting from mechanical
32+
transformation or translation of a Source form, including but
33+
not limited to compiled object code, generated documentation,
34+
and conversions to other media types.
35+
36+
"Work" shall mean the work of authorship, whether in Source or
37+
Object form, made available under the License, as indicated by a
38+
copyright notice that is included in or attached to the work
39+
(an example is provided in the Appendix below).
40+
41+
"Derivative Works" shall mean any work, whether in Source or Object
42+
form, that is based on (or derived from) the Work and for which the
43+
editorial revisions, annotations, elaborations, or other modifications
44+
represent, as a whole, an original work of authorship. For the purposes
45+
of this License, Derivative Works shall not include works that remain
46+
separable from, or merely link (or bind by name) to the interfaces of,
47+
the Work and Derivative Works thereof.
48+
49+
"Contribution" shall mean any work of authorship, including
50+
the original version of the Work and any modifications or additions
51+
to that Work or Derivative Works thereof, that is intentionally
52+
submitted to Licensor for inclusion in the Work by the copyright owner
53+
or by an individual or Legal Entity authorized to submit on behalf of
54+
the copyright owner. For the purposes of this definition, "submitted"
55+
means any form of electronic, verbal, or written communication sent
56+
to the Licensor or its representatives, including but not limited to
57+
communication on electronic mailing lists, source code control systems,
58+
and issue tracking systems that are managed by, or on behalf of, the
59+
Licensor for the purpose of discussing and improving the Work, but
60+
excluding communication that is conspicuously marked or otherwise
61+
designated in writing by the copyright owner as "Not a Contribution."
62+
63+
"Contributor" shall mean Licensor and any individual or Legal Entity
64+
on behalf of whom a Contribution has been received by Licensor and
65+
subsequently incorporated within the Work.
66+
67+
2. Grant of Copyright License. Subject to the terms and conditions of
68+
this License, each Contributor hereby grants to You a perpetual,
69+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70+
copyright license to reproduce, prepare Derivative Works of,
71+
publicly display, publicly perform, sublicense, and distribute the
72+
Work and such Derivative Works in Source or Object form.
73+
74+
3. Grant of Patent License. Subject to the terms and conditions of
75+
this License, each Contributor hereby grants to You a perpetual,
76+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77+
(except as stated in this section) patent license to make, have made,
78+
use, offer to sell, sell, import, and otherwise transfer the Work,
79+
where such license applies only to those patent claims licensable
80+
by such Contributor that are necessarily infringed by their
81+
Contribution(s) alone or by combination of their Contribution(s)
82+
with the Work to which such Contribution(s) was submitted. If You
83+
institute patent litigation against any entity (including a
84+
cross-claim or counterclaim in a lawsuit) alleging that the Work
85+
or a Contribution incorporated within the Work constitutes direct
86+
or contributory patent infringement, then any patent licenses
87+
granted to You under this License for that Work shall terminate
88+
as of the date such litigation is filed.
89+
90+
4. Redistribution. You may reproduce and distribute copies of the
91+
Work or Derivative Works thereof in any medium, with or without
92+
modifications, and in Source or Object form, provided that You
93+
meet the following conditions:
94+
95+
(a) You must give any other recipients of the Work or
96+
Derivative Works a copy of this License; and
97+
98+
(b) You must cause any modified files to carry prominent notices
99+
stating that You changed the files; and
100+
101+
(c) You must retain, in the Source form of any Derivative Works
102+
that You distribute, all copyright, patent, trademark, and
103+
attribution notices from the Source form of the Work,
104+
excluding those notices that do not pertain to any part of
105+
the Derivative Works; and
106+
107+
(d) If the Work includes a "NOTICE" text file as part of its
108+
distribution, then any Derivative Works that You distribute must
109+
include a readable copy of the attribution notices contained
110+
within such NOTICE file, excluding those notices that do not
111+
pertain to any part of the Derivative Works, in at least one
112+
of the following places: within a NOTICE text file distributed
113+
as part of the Derivative Works; within the Source form or
114+
documentation, if provided along with the Derivative Works; or,
115+
within a display generated by the Derivative Works, if and
116+
wherever such third-party notices normally appear. The contents
117+
of the NOTICE file are for informational purposes only and
118+
do not modify the License. You may add Your own attribution
119+
notices within Derivative Works that You distribute, alongside
120+
or as an addendum to the NOTICE text from the Work, provided
121+
that such additional attribution notices cannot be construed
122+
as modifying the License.
123+
124+
You may add Your own copyright statement to Your modifications and
125+
may provide additional or different license terms and conditions
126+
for use, reproduction, or distribution of Your modifications, or
127+
for any such Derivative Works as a whole, provided Your use,
128+
reproduction, and distribution of the Work otherwise complies with
129+
the conditions stated in this License.
130+
131+
5. Submission of Contributions. Unless You explicitly state otherwise,
132+
any Contribution intentionally submitted for inclusion in the Work
133+
by You to the Licensor shall be under the terms and conditions of
134+
this License, without any additional terms or conditions.
135+
Notwithstanding the above, nothing herein shall supersede or modify
136+
the terms of any separate license agreement you may have executed
137+
with Licensor regarding such Contributions.
138+
139+
6. Trademarks. This License does not grant permission to use the trade
140+
names, trademarks, service marks, or product names of the Licensor,
141+
except as required for reasonable and customary use in describing the
142+
origin of the Work and reproducing the content of the NOTICE file.
143+
144+
7. Disclaimer of Warranty. Unless required by applicable law or
145+
agreed to in writing, Licensor provides the Work (and each
146+
Contributor provides its Contributions) on an "AS IS" BASIS,
147+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148+
implied, including, without limitation, any warranties or conditions
149+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150+
PARTICULAR PURPOSE. You are solely responsible for determining the
151+
appropriateness of using or redistributing the Work and assume any
152+
risks associated with Your exercise of permissions under this License.
153+
154+
8. Limitation of Liability. In no event and under no legal theory,
155+
whether in tort (including negligence), contract, or otherwise,
156+
unless required by applicable law (such as deliberate and grossly
157+
negligent acts) or agreed to in writing, shall any Contributor be
158+
liable to You for damages, including any direct, indirect, special,
159+
incidental, or consequential damages of any character arising as a
160+
result of this License or out of the use or inability to use the
161+
Work (including but not limited to damages for loss of goodwill,
162+
work stoppage, computer failure or malfunction, or any and all
163+
other commercial damages or losses), even if such Contributor
164+
has been advised of the possibility of such damages.
165+
166+
9. Accepting Warranty or Additional Liability. While redistributing
167+
the Work or Derivative Works thereof, You may choose to offer,
168+
and charge a fee for, acceptance of support, warranty, indemnity,
169+
or other liability obligations and/or rights consistent with this
170+
License. However, in accepting such obligations, You may act only
171+
on Your own behalf and on Your sole responsibility, not on behalf
172+
of any other Contributor, and only if You agree to indemnify,
173+
defend, and hold each Contributor harmless for any liability
174+
incurred by, or claims asserted against, such Contributor by reason
175+
of your accepting any such warranty or additional liability.
176+
177+
END OF TERMS AND CONDITIONS
178+
179+
APPENDIX: How to apply the Apache License to your work.
180+
181+
To apply the Apache License to your work, attach the following
182+
boilerplate notice, with the fields enclosed by brackets "[]"
183+
replaced with your own identifying information. (Don't include
184+
the brackets!) The text should be enclosed in the appropriate
185+
comment syntax for the file format. We also recommend that a
186+
file or class name and description of purpose be included on the
187+
same "printed page" as the copyright notice for easier
188+
identification within third-party archives.
189+
190+
Copyright [yyyy] [name of copyright owner]
191+
192+
Licensed under the Apache License, Version 2.0 (the "License");
193+
you may not use this file except in compliance with the License.
194+
You may obtain a copy of the License at
195+
196+
http://www.apache.org/licenses/LICENSE-2.0
197+
198+
Unless required by applicable law or agreed to in writing, software
199+
distributed under the License is distributed on an "AS IS" BASIS,
200+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201+
See the License for the specific language governing permissions and
202+
limitations under the License.

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#Multi-Jvm
2+
This projects provides a few helper classes to allow easy creation and
3+
destruction of multiple JVMs from inside an integration test.
4+
5+
The main inspiration came from working with the [sbt-multi-jvm-plugin](https://github.com/sbt/sbt-multi-jvm)
6+
7+
This is a cleanroom implementaion that is NOT based on the code from sbt-multi-jvm.
8+
9+
#Why?
10+
When working with distributed systems (Vert.x, Akka, Quasar, ...) it is
11+
useful to test certain behavior from the outside (serialization,
12+
leader election, memory usage, ...). Spawning a small cluster using the
13+
code included in this project is quite simple and should enable testing
14+
of complex interaction scenarios (well, at least that's what I hope ...)
15+
16+
#Usage
17+
Check out and do ```mvn clean install```
18+
Add the dependency to your project:
19+
```xml
20+
<dependency>
21+
<groupId>de.codeptibull</groupId>
22+
<artifactId>multi-jvm-runner</artifactId>
23+
<version>1.0-SNAPSHOT</version>
24+
<scope>test</test>
25+
</dependency>
26+
```
27+
28+
In your test spawn the process:
29+
```java
30+
import de.codeptibull.maven.multijvm.JvmProcess
31+
32+
JvmProcess proc = JvmProcess.builder().addCurrentClasspath().mainClass(JvmTest.class.getName()).build();
33+
34+
proc.waitFor();
35+
36+
```
37+
38+
#Demo
39+
Take a look into the test-sources in *src/test/java/de/codepitbull/multijvm/vertx* for a full example.
40+
41+
#Why no Maven?
42+
I initially thought about writing a Maven plugin to use this. It didn't
43+
really make sense as Maven's phases are a lot more static than those of
44+
sbt. I might continue if someone comes up with a good case for such a
45+
plugin.

pom.xml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>de.codeptibull</groupId>
5+
<artifactId>multi-jvm-runner</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>multi-jvm Runner</name>
9+
<licenses>
10+
<license>
11+
<name>The Apache Software License, Version 2.0</name>
12+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
13+
<distribution>repo</distribution>
14+
</license>
15+
</licenses>
16+
<properties>
17+
<maven.compiler.source>1.8</maven.compiler.source>
18+
<maven.compiler.target>1.8</maven.compiler.target>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
21+
<junit.version>4.12</junit.version>
22+
<vertx.version>3.3.0</vertx.version>
23+
</properties>
24+
<dependencies>
25+
<dependency>
26+
<groupId>junit</groupId>
27+
<artifactId>junit</artifactId>
28+
<version>${junit.version}</version>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>io.vertx</groupId>
33+
<artifactId>vertx-core</artifactId>
34+
<version>${vertx.version}</version>
35+
<scope>test</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>io.vertx</groupId>
39+
<artifactId>vertx-hazelcast</artifactId>
40+
<version>${vertx.version}</version>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package de.codeptibull.multijvm;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.io.InputStreamReader;
7+
import java.util.List;
8+
import java.util.concurrent.CopyOnWriteArrayList;
9+
import java.util.function.Consumer;
10+
11+
public class InputStreamProcessor {
12+
private InputStream inputStream;
13+
private List<Consumer<String>> consumerList = new CopyOnWriteArrayList<>();
14+
private Thread thread;
15+
private volatile boolean stop = false;
16+
17+
public InputStreamProcessor(InputStream inputStream) {
18+
this.inputStream = inputStream;
19+
thread = new Thread() {
20+
@Override
21+
public void run() {
22+
try {
23+
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
24+
String line;
25+
while (((line = br.readLine()) != null) && !stop) {
26+
for (Consumer<String> c : consumerList) {
27+
c.accept(line);
28+
}
29+
}
30+
}
31+
} catch (IOException ioe) {
32+
throw new RuntimeException(ioe);
33+
}
34+
}
35+
};
36+
}
37+
38+
public InputStreamProcessor addConsumer(Consumer<String> consumer) {
39+
consumerList.add(consumer);
40+
return this;
41+
}
42+
43+
public InputStreamProcessor removeConsumer(Consumer<String> consumer) {
44+
consumerList.remove(consumer);
45+
return this;
46+
}
47+
48+
public InputStreamProcessor start() {
49+
thread.start();
50+
return this;
51+
}
52+
53+
public InputStreamProcessor stop() {
54+
stop = true;
55+
thread.interrupt();
56+
return this;
57+
}
58+
}

0 commit comments

Comments
 (0)