Skip to content

Commit af06609

Browse files
committed
Add build infrastructure.
1 parent be5dae4 commit af06609

File tree

4 files changed

+190
-0
lines changed

4 files changed

+190
-0
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
# RxJavaBridge
22
Bridge between RxJava 2 and RxJava 3
3+
4+
<a href='https://travis-ci.org/akarnokd/RxJavaBridge/builds'><img src='https://travis-ci.org/akarnokd/RxJavaBridge.svg?branch=master'></a>
5+
[![codecov.io](http://codecov.io/github/akarnokd/RxJavaBridge/coverage.svg?branch=master)](http://codecov.io/github/akarnokd/RxJavaBridge?branch=master)
6+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.akarnokd/rxjava3-bridge/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.akarnokd/rxjava3-bridge)
7+
8+
RxJava 2: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava2/rxjava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava2/rxjava)
9+
10+
RxJava 3: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava3/rxjava/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.reactivex.rxjava3/rxjava)
11+
12+
13+
```groovy
14+
15+
dependencies {
16+
implementation "com.github.akarnokd:rxjava3-bridge:3.0.0-RC2"
17+
}
18+
```
19+
20+
21+
# Features
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2019 David Karnok
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 hu.akarnokd.rxjava3.bridge;
18+
19+
/**
20+
* Utility class to convert between RxJava 2 and RxJava 3 components.
21+
* @since 3.0.0
22+
*/
23+
public final class RxJavaBridge {
24+
25+
private RxJavaBridge() {
26+
throw new IllegalStateException("No instances!");
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2019 David Karnok
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 hu.akarnokd.rxjava3.bridge;
18+
19+
import org.junit.Test;
20+
21+
public class RxJavaBridgeTest {
22+
23+
@Test
24+
public void utilityClass() {
25+
TestHelper.checkUtilityClass(RxJavaBridge.class);
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright 2019 David Karnok
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 hu.akarnokd.rxjava3.bridge;
18+
19+
import static org.junit.Assert.*;
20+
21+
import java.lang.reflect.*;
22+
import java.util.*;
23+
import java.util.concurrent.*;
24+
25+
import io.reactivex.rxjava3.core.Scheduler;
26+
import io.reactivex.rxjava3.schedulers.Schedulers;
27+
28+
public final class TestHelper {
29+
30+
private TestHelper() {
31+
throw new IllegalStateException("No instances!");
32+
}
33+
34+
/**
35+
* Validates that the given class, when forcefully instantiated throws
36+
* an IllegalArgumentException("No instances!") exception.
37+
* @param clazz the class to test, not null
38+
*/
39+
public static void checkUtilityClass(Class<?> clazz) {
40+
try {
41+
Constructor<?> c = clazz.getDeclaredConstructor();
42+
43+
c.setAccessible(true);
44+
45+
try {
46+
c.newInstance();
47+
fail("Should have thrown InvocationTargetException(IllegalStateException)");
48+
} catch (InvocationTargetException ex) {
49+
assertEquals("No instances!", ex.getCause().getMessage());
50+
}
51+
} catch (Exception ex) {
52+
AssertionError ae = new AssertionError(ex.toString());
53+
ae.initCause(ex);
54+
throw ae;
55+
}
56+
}
57+
58+
/**
59+
* Checks if tasks can be immediately executed on the computation scheduler.
60+
* @throws ObstructionException if the schedulers don't respond within 1 second
61+
*/
62+
public static void checkObstruction() {
63+
final int ncpu = Runtime.getRuntime().availableProcessors();
64+
65+
final CountDownLatch cdl = new CountDownLatch(ncpu);
66+
final List<Scheduler.Worker> workers = new ArrayList<Scheduler.Worker>();
67+
final Runnable task = new Runnable() {
68+
@Override
69+
public void run() {
70+
cdl.countDown();
71+
}
72+
};
73+
74+
for (int i = 0; i < ncpu; i++) {
75+
workers.add(Schedulers.computation().createWorker());
76+
}
77+
for (Scheduler.Worker w : workers) {
78+
w.schedule(task);
79+
}
80+
try {
81+
if (!cdl.await(5, TimeUnit.SECONDS)) {
82+
int cnt = 0;
83+
StringBuilder sb = new StringBuilder();
84+
for (Map.Entry<Thread, StackTraceElement[]> e : Thread.getAllStackTraces().entrySet()) {
85+
if (e.getKey().getName().contains("Computation")) {
86+
cnt++;
87+
sb.append("Thread: ").append(e.getKey()).append("\r\n");
88+
for (StackTraceElement entry : e.getValue()) {
89+
sb.append(" at ").append(entry).append("\r\n");
90+
}
91+
}
92+
}
93+
94+
RuntimeException ex = new ObstructionException("Obstruction/Timeout detected! ncpu = " + ncpu + ", computation workers = " + cnt + "\r\n" + sb);
95+
96+
throw ex;
97+
}
98+
} catch (InterruptedException ex) {
99+
throw new ObstructionException("Interrupted: " + ex);
100+
} finally {
101+
for (Scheduler.Worker w : workers) {
102+
w.dispose();
103+
}
104+
}
105+
}
106+
/**
107+
* Exception thrown if obstruction was detected.
108+
*/
109+
public static final class ObstructionException extends RuntimeException {
110+
private static final long serialVersionUID = -6380717994471291795L;
111+
public ObstructionException(String message) {
112+
super(message);
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)