-
Notifications
You must be signed in to change notification settings - Fork 916
[PR for discussion] Showing Reactive Streams TCK, proposing some #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7a8b91b
c1c8df7
b2e5d0f
92221d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ public ResponseT complete() { | |
/** | ||
* {@link Subscriber} implementation that writes chunks to a file. | ||
*/ | ||
// FIXME cover with Reactive Streams TCK, looks ok from a first brief look, but could be missing some edge cases | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is not (at least yet), intended to be merged, please assume those are just markers for myself to know where/how many implementations are there and what we should cover with tests. |
||
private class FileSubscriber implements Subscriber<ByteBuffer> { | ||
|
||
private volatile boolean writeInProgress = false; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ static String userAgent() { | |
|
||
ua = ua | ||
.replace("{platform}", "java") | ||
.replace("{version}", VersionInfo.SDK_VERSION) | ||
.replace("{version}", "MOCK")//VersionInfo.SDK_VERSION) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FIXME: had a compile error here, remove in case we'd intend to merge this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you run a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
.replace("{os.name}", replaceSpaces(JavaSystemSetting.OS_NAME.getStringValue().orElse(null))) | ||
.replace("{os.version}", replaceSpaces(JavaSystemSetting.OS_VERSION.getStringValue().orElse(null))) | ||
.replace("{java.vm.name}", replaceSpaces(JavaSystemSetting.JAVA_VM_NAME.getStringValue().orElse(null))) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.core.async; | ||
|
||
import org.junit.Test; | ||
import org.reactivestreams.Publisher; | ||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.tck.TestEnvironment; | ||
import software.amazon.awssdk.http.async.SimpleSubscriber; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import com.google.common.jimfs.Configuration; | ||
import com.google.common.jimfs.Jimfs; | ||
|
||
public class FileAsyncRequestPublisherTckTest extends org.reactivestreams.tck.PublisherVerification<ByteBuffer> { | ||
|
||
// same as `FileAsyncRequestProvider.DEFAULT_CHUNK_SIZE`: | ||
final int DEFAULT_CHUNK_SIZE = 16 * 1024; | ||
final int ELEMENTS = 1000; | ||
|
||
// mock file system: | ||
final FileSystem fs = Jimfs.newFileSystem(Configuration.unix()); | ||
|
||
final Path testFile; | ||
final Path doestNotExist; | ||
|
||
public FileAsyncRequestPublisherTckTest() throws IOException { | ||
super(new TestEnvironment()); | ||
testFile = Files.createFile(fs.getPath("/test-file.tmp")); | ||
|
||
doestNotExist = new File("does-not-exist").toPath(); | ||
|
||
final BufferedWriter writer = Files.newBufferedWriter(testFile); | ||
|
||
final char[] chars = new char[DEFAULT_CHUNK_SIZE]; | ||
Arrays.fill(chars, 'A'); | ||
|
||
for (int i = 0; i < ELEMENTS; i++) { | ||
writer.write(chars); // write one chunk | ||
} | ||
} | ||
|
||
@Override | ||
public Publisher<ByteBuffer> createPublisher(long elements) { | ||
if (elements < ELEMENTS) return AsyncRequestProvider.fromFile(testFile); | ||
else return null; // we don't support more elements | ||
} | ||
|
||
@Override | ||
public Publisher<ByteBuffer> createFailedPublisher() { | ||
// tests properly failing on non existing files: | ||
return AsyncRequestProvider.fromFile(doestNotExist); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.core.async; | ||
|
||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.tck.TestEnvironment; | ||
import software.amazon.awssdk.http.async.SimpleSubscriber; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class SimpleSubscriberTckTest extends org.reactivestreams.tck.SubscriberBlackboxVerification<ByteBuffer> { | ||
|
||
public SimpleSubscriberTckTest() { | ||
super(new TestEnvironment()); | ||
} | ||
|
||
@Override | ||
public Subscriber<ByteBuffer> createSubscriber() { | ||
return new SimpleSubscriber(buffer -> { | ||
// ignore | ||
}); | ||
} | ||
|
||
@Override | ||
public ByteBuffer createElement(int i) { | ||
return ByteBuffer.wrap(String.valueOf(i).getBytes()); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's interesting that you had to explicitly pull this in - was this required or was it just a best practise thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly just since I wanted to be on 1.0.2 and I think the Netty adapter library is on previous version. I will double check. It is backwards compatible, so we can use a newer version here (both semantically and binary)