Skip to content

Commit 08ad956

Browse files
authored
fix: JS viewports must allow subscription to be changed while waiting (#6473)
Fixes DH-18128
1 parent 5c680c8 commit 08ad956

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

web/client-api/src/main/java/io/deephaven/web/client/api/subscription/AbstractTableSubscription.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public abstract class AbstractTableSubscription extends HasEventHandling {
6464
protected enum Status {
6565
/** Waiting for some prerequisite before we can use it for the first time. */
6666
STARTING,
67+
/** All prerequisites are met, waiting for the first snapshot to be returned. */
68+
SUBSCRIPTION_REQUESTED,
6769
/** Successfully created, not waiting for any messages to be accurate. */
6870
ACTIVE,
6971
/** Waiting for an update to return from being active to being active again. */
@@ -117,7 +119,11 @@ protected void revive() {
117119
WebBarrageSubscription.ViewportChangedHandler viewportChangedHandler = this::onViewportChange;
118120
WebBarrageSubscription.DataChangedHandler dataChangedHandler = this::onDataChanged;
119121

120-
status = Status.ACTIVE;
122+
status = Status.SUBSCRIPTION_REQUESTED;
123+
124+
// In order to create the subscription, we need to already have the table resolved, so we know if it
125+
// is a blink table or not. In turn, we can't be prepared to handle any messages from the server until
126+
// we know this, so we can't race messages with this design.
121127
this.barrageSubscription = WebBarrageSubscription.subscribe(
122128
subscriptionType, state, viewportChangedHandler, dataChangedHandler);
123129

@@ -164,7 +170,8 @@ protected static FlatBufferBuilder subscriptionRequest(byte[] tableTicket, BitSe
164170

165171
protected abstract void sendFirstSubscriptionRequest();
166172

167-
protected void sendBarrageSubscriptionRequest(RangeSet viewport, JsArray<Column> columns, Double updateIntervalMs,
173+
protected void sendBarrageSubscriptionRequest(@Nullable RangeSet viewport, JsArray<Column> columns,
174+
Double updateIntervalMs,
168175
boolean isReverseViewport) {
169176
if (isClosed()) {
170177
if (failMsg == null) {
@@ -173,7 +180,9 @@ protected void sendBarrageSubscriptionRequest(RangeSet viewport, JsArray<Column>
173180
throw new IllegalStateException("Can't change subscription, already failed: " + failMsg);
174181
}
175182
}
176-
status = Status.PENDING_UPDATE;
183+
if (status == Status.ACTIVE) {
184+
status = Status.PENDING_UPDATE;
185+
}
177186
this.columns = columns;
178187
this.viewportRowSet = viewport;
179188
this.columnBitSet = makeColumnBitset(columns);

web/client-api/src/main/java/io/deephaven/web/client/api/subscription/TableViewportSubscription.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public void setViewport(double firstRow, double lastRow, @JsOptional @JsNullable
248248

249249
public void setInternalViewport(double firstRow, double lastRow, Column[] columns, Double updateIntervalMs,
250250
Boolean isReverseViewport) {
251+
// Until we've created the stream, we just cache the requested viewport
251252
if (status == Status.STARTING) {
252253
this.firstRow = firstRow;
253254
this.lastRow = lastRow;

web/client-api/src/test/java/io/deephaven/web/client/api/subscription/ViewportTestGwt.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ public void testViewportOnStaticTable() {
9393
.then(this::finish).catch_(this::report);
9494
}
9595

96+
public void testChangePendingViewport() {
97+
connect(tables)
98+
.then(table("staticTable"))
99+
.then(table -> {
100+
delayTestFinish(5001);
101+
102+
table.setViewport(0, 25, null);
103+
assertEquals(100.0, table.getSize());
104+
return Promise.resolve(table);
105+
})
106+
.then(table -> {
107+
assertEquals(100.0, table.getSize());
108+
table.setViewport(5, 30, null);
109+
assertEquals(100.0, table.getSize());
110+
return assertUpdateReceived(table, viewport -> {
111+
assertEquals(100.0, table.getSize());
112+
113+
assertEquals(5d, viewport.getOffset());
114+
assertEquals(26, viewport.getRows().length);
115+
}, 2500);
116+
})
117+
.then(table -> {
118+
assertEquals(100.0, table.getSize());
119+
table.close();
120+
return null;
121+
})
122+
.then(this::finish).catch_(this::report);
123+
}
124+
96125
// TODO: https://deephaven.atlassian.net/browse/DH-11196
97126
public void ignore_testViewportOnGrowingTable() {
98127
connect(tables)

0 commit comments

Comments
 (0)