-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.x: add offer() method to Publish & Behavior Processors (#5184)
* 2.x: add offer() method to Publish & Behavior Processors * Sleep instead of yield.
- Loading branch information
Showing
11 changed files
with
602 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/io/reactivex/tck/AsyncProcessorAsPublisherTckTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright (c) 2016-present, RxJava Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See | ||
* the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.reactivex.tck; | ||
|
||
import org.reactivestreams.Publisher; | ||
import org.testng.annotations.Test; | ||
|
||
import io.reactivex.processors.AsyncProcessor; | ||
import io.reactivex.schedulers.Schedulers; | ||
|
||
@Test | ||
public class AsyncProcessorAsPublisherTckTest extends BaseTck<Integer> { | ||
|
||
public AsyncProcessorAsPublisherTckTest() { | ||
super(100); | ||
} | ||
|
||
@Override | ||
public Publisher<Integer> createPublisher(final long elements) { | ||
final AsyncProcessor<Integer> pp = AsyncProcessor.create(); | ||
|
||
Schedulers.io().scheduleDirect(new Runnable() { | ||
@Override | ||
public void run() { | ||
long start = System.currentTimeMillis(); | ||
while (!pp.hasSubscribers()) { | ||
try { | ||
Thread.sleep(1); | ||
} catch (InterruptedException ex) { | ||
return; | ||
} | ||
|
||
if (System.currentTimeMillis() - start > 200) { | ||
return; | ||
} | ||
} | ||
|
||
for (int i = 0; i < elements; i++) { | ||
pp.onNext(i); | ||
} | ||
pp.onComplete(); | ||
} | ||
}); | ||
return pp; | ||
} | ||
|
||
@Override | ||
public long maxElementsFromPublisher() { | ||
return 1; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/io/reactivex/tck/BehaviorProcessorAsPublisherTckTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) 2016-present, RxJava Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See | ||
* the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.reactivex.tck; | ||
|
||
import org.reactivestreams.Publisher; | ||
import org.testng.annotations.Test; | ||
|
||
import io.reactivex.processors.BehaviorProcessor; | ||
import io.reactivex.schedulers.Schedulers; | ||
|
||
@Test | ||
public class BehaviorProcessorAsPublisherTckTest extends BaseTck<Integer> { | ||
|
||
@Override | ||
public Publisher<Integer> createPublisher(final long elements) { | ||
final BehaviorProcessor<Integer> pp = BehaviorProcessor.create(); | ||
|
||
Schedulers.io().scheduleDirect(new Runnable() { | ||
@Override | ||
public void run() { | ||
long start = System.currentTimeMillis(); | ||
while (!pp.hasSubscribers()) { | ||
try { | ||
Thread.sleep(1); | ||
} catch (InterruptedException ex) { | ||
return; | ||
} | ||
|
||
if (System.currentTimeMillis() - start > 200) { | ||
return; | ||
} | ||
} | ||
|
||
for (int i = 0; i < elements; i++) { | ||
while (!pp.offer(i)) { | ||
Thread.yield(); | ||
if (System.currentTimeMillis() - start > 1000) { | ||
return; | ||
} | ||
} | ||
} | ||
pp.onComplete(); | ||
} | ||
}); | ||
return pp; | ||
} | ||
} |
Oops, something went wrong.