Skip to content

StreamIdSupplier returns 1,3,5... or 2,4,6... #213

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 3 commits into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private void handleFrame(int streamId, FrameType type, Frame frame) {
}

private void handleMissingResponseProcessor(int streamId, FrameType type, Frame frame) {
if (!streamIdSupplier.isValid(streamId)) {
if (!streamIdSupplier.isBeforeOrCurrent(streamId)) {
if (type == FrameType.ERROR) {
// message for stream that has never existed, we have a problem with
// the overall connection and must tear down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public synchronized int nextStreamId() {
return streamId;
}

public synchronized boolean isValid(int streamId) {
return this.streamId < streamId;
public synchronized boolean isBeforeOrCurrent(int streamId) {
return this.streamId >= streamId && streamId > 0;
}

public static StreamIdSupplier clientSupplier() {
return new StreamIdSupplier(1);
return new StreamIdSupplier(-1);
}

public static StreamIdSupplier serverSupplier() {
return new StreamIdSupplier(2);
return new StreamIdSupplier(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.reactivesocket;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class StreamIdSupplierTest {
@Test
public void testClientSequence() {
StreamIdSupplier s = StreamIdSupplier.clientSupplier();
assertEquals(1, s.nextStreamId());
assertEquals(3, s.nextStreamId());
assertEquals(5, s.nextStreamId());
}

@Test
public void testServerSequence() {
StreamIdSupplier s = StreamIdSupplier.serverSupplier();
assertEquals(2, s.nextStreamId());
assertEquals(4, s.nextStreamId());
assertEquals(6, s.nextStreamId());
}

@Test
public void testClientIsValid() {
StreamIdSupplier s = StreamIdSupplier.clientSupplier();

assertFalse(s.isBeforeOrCurrent(1));
assertFalse(s.isBeforeOrCurrent(3));

s.nextStreamId();
assertTrue(s.isBeforeOrCurrent(1));
assertFalse(s.isBeforeOrCurrent(3));

s.nextStreamId();
assertTrue(s.isBeforeOrCurrent(3));

// negative
assertFalse(s.isBeforeOrCurrent(-1));
// connection
assertFalse(s.isBeforeOrCurrent(0));
// server also accepted (checked externally)
assertTrue(s.isBeforeOrCurrent(2));
}

@Test
public void testServerIsValid() {
StreamIdSupplier s = StreamIdSupplier.serverSupplier();

assertFalse(s.isBeforeOrCurrent(2));
assertFalse(s.isBeforeOrCurrent(4));

s.nextStreamId();
assertTrue(s.isBeforeOrCurrent(2));
assertFalse(s.isBeforeOrCurrent(4));

s.nextStreamId();
assertTrue(s.isBeforeOrCurrent(4));

// negative
assertFalse(s.isBeforeOrCurrent(-2));
// connection
assertFalse(s.isBeforeOrCurrent(0));
// client also accepted (checked externally)
assertTrue(s.isBeforeOrCurrent(1));
}
}