-
Notifications
You must be signed in to change notification settings - Fork 9.3k
refactor(SSE): move static functions to extensions #9010
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
42d80df
refactor(SSE): move static functions to extensions
MukjepScarlet 3cd0797
comments
MukjepScarlet 333112d
redirect to new function
MukjepScarlet 8ebd9c8
a simple test (in java)
MukjepScarlet 914ce4a
spotlessApply
MukjepScarlet bd3395f
fix java test
MukjepScarlet 1347c08
rename function for Response
MukjepScarlet b3e7a98
rename
MukjepScarlet 1bcd168
restrictive access
MukjepScarlet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
84 changes: 84 additions & 0 deletions
84
okhttp-sse/src/test/java/okhttp3/sse/internal/EventSourceFactoryTest.java
This file contains hidden or 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,84 @@ | ||
| /* | ||
| * Copyright (C) 2018 Square, Inc. | ||
| * | ||
| * 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 okhttp3.sse.internal; | ||
|
|
||
| import mockwebserver3.MockResponse; | ||
| import mockwebserver3.MockWebServer; | ||
| import mockwebserver3.junit5.StartStop; | ||
| import okhttp3.OkHttpClient; | ||
| import okhttp3.Request; | ||
| import okhttp3.Response; | ||
| import okhttp3.sse.EventSource; | ||
| import okhttp3.sse.EventSourceListener; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| public class EventSourceFactoryTest { | ||
|
|
||
| @StartStop | ||
| private final MockWebServer server = new MockWebServer(); | ||
|
|
||
| @Test | ||
| public void testEventSourceFactory() throws Exception { | ||
| OkHttpClient client = new OkHttpClient(); | ||
| EventSource.Factory factory = EventSource.Factory.create(client); | ||
| server.enqueue( | ||
| new MockResponse.Builder() | ||
| .body("data: hello\n\n") | ||
| .setHeader("content-type", "text/event-stream") | ||
| .build() | ||
| ); | ||
| Request request = new Request.Builder().url(server.url("/")).build(); | ||
| CompletableFuture<Void> future = new CompletableFuture<>(); | ||
| factory.newEventSource(request, new EventSourceListener() { | ||
| @Override | ||
| public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) { | ||
| try { | ||
| assertEquals("text/event-stream", response.request().header("Accept")); | ||
| } catch (Exception e) { | ||
| future.completeExceptionally(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onEvent(@NotNull EventSource eventSource, @Nullable String id, @Nullable String type, @NotNull String data) { | ||
| try { | ||
| assertEquals("hello", data); | ||
| future.complete(null); | ||
| } catch (Exception e) { | ||
| future.completeExceptionally(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onClosed(@NotNull EventSource eventSource) { | ||
| future.completeExceptionally(new IllegalStateException("closed")); | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(@NotNull EventSource eventSource, @Nullable Throwable t, @Nullable Response response) { | ||
| future.completeExceptionally(t == null ? new NullPointerException() : t); | ||
| } | ||
| }); | ||
| future.get(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.