Skip to content

Commit 305cd28

Browse files
committed
Use nested context in java TestStream
1 parent 5485467 commit 305cd28

4 files changed

Lines changed: 13 additions & 31 deletions

File tree

runners/prism/java/build.gradle

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,14 @@ def sickbayTests = [
106106

107107
// Prism doesn't support multiple TestStreams.
108108
'org.apache.beam.sdk.testing.TestStreamTest.testMultipleStreams',
109-
// Sometimes fails missing a final 'AFTER'. Otherwise, Hangs in ElementManager.FailBundle due to a held stageState lock.
110-
'org.apache.beam.sdk.testing.TestStreamTest.testMultiStage',
111109

112110
// GroupIntoBatchesTest tests that fail:
113-
// Teststream has bad KV encodings due to using an outer context.
114-
'org.apache.beam.sdk.transforms.GroupIntoBatchesTest.testInStreamingMode',
115-
'org.apache.beam.sdk.transforms.GroupIntoBatchesTest.testBufferingTimerInFixedWindow',
116-
// sdk worker disconnected
117-
'org.apache.beam.sdk.transforms.GroupIntoBatchesTest.testBufferingTimerInGlobalWindow',
111+
// Wrong number of elements in windows after GroupIntoBatches: null
112+
// Incorrect output collection after GroupIntoBatches: null
113+
// 'org.apache.beam.sdk.transforms.GroupIntoBatchesTest.testInStreamingMode',
114+
// 'org.apache.beam.sdk.transforms.GroupIntoBatchesTest.testBufferingTimerInFixedWindow',
115+
// varint overflow 4120879041988 on counting step
116+
// 'org.apache.beam.sdk.transforms.GroupIntoBatchesTest.testBufferingTimerInGlobalWindow',
118117
// ShardedKey not yet implemented.
119118
'org.apache.beam.sdk.transforms.GroupIntoBatchesTest.testWithShardedKeyInGlobalWindow',
120119

sdks/go/pkg/beam/runners/prism/internal/execute.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package internal
1717

1818
import (
19-
"bytes"
2019
"context"
2120
"errors"
2221
"fmt"
@@ -27,7 +26,6 @@ import (
2726
"sync/atomic"
2827
"time"
2928

30-
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/coder"
3129
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/mtime"
3230
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/exec"
3331
pipepb "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v1"
@@ -277,33 +275,14 @@ func executePipeline(ctx context.Context, wks map[string]*worker.W, j *jobservic
277275
}
278276

279277
// Ensure awareness of the coder used for the teststream.
280-
cID, err := lpUnknownCoders(pyld.GetCoderId(), coders, comps.GetCoders())
278+
_, err := lpUnknownCoders(pyld.GetCoderId(), coders, comps.GetCoders())
281279
if err != nil {
282280
panic(err)
283281
}
284282
mayLP := func(v []byte) []byte {
285283
//slog.Warn("teststream bytes", "value", string(v), "bytes", v)
286284
return v
287285
}
288-
// Hack for Java Strings in test stream, since it doesn't encode them correctly.
289-
forceLP := cID == "StringUtf8Coder" || cID != pyld.GetCoderId()
290-
if forceLP {
291-
// slog.Warn("recoding TestStreamValue", "cID", cID, "newUrn", coders[cID].GetSpec().GetUrn(), "payloadCoder", pyld.GetCoderId(), "oldUrn", coders[pyld.GetCoderId()].GetSpec().GetUrn())
292-
// The coder needed length prefixing. For simplicity, add a length prefix to each
293-
// encoded element, since we will be sending a length prefixed coder to consume
294-
// this anyway. This is simpler than trying to find all the re-written coders after the fact.
295-
mayLP = func(v []byte) []byte {
296-
var buf bytes.Buffer
297-
if err := coder.EncodeVarInt((int64)(len(v)), &buf); err != nil {
298-
panic(err)
299-
}
300-
if _, err := buf.Write(v); err != nil {
301-
panic(err)
302-
}
303-
//slog.Warn("teststream bytes - after LP", "value", string(v), "bytes", buf.Bytes())
304-
return buf.Bytes()
305-
}
306-
}
307286

308287
tsb := em.AddTestStream(stage.ID, t.Outputs)
309288
for _, e := range pyld.GetEvents() {

sdks/go/pkg/beam/runners/prism/internal/preprocess.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/jobservices"
2828
"github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/urns"
2929
"golang.org/x/exp/maps"
30+
"google.golang.org/protobuf/encoding/prototext"
3031
"google.golang.org/protobuf/proto"
3132
)
3233

@@ -152,6 +153,7 @@ func (p *preprocessor) preProcessGraph(comps *pipepb.Components, j *jobservices.
152153
}
153154

154155
// Extract URNs for the given transform.
156+
slog.Debug("components in pipeline proto", "proto", prototext.Format(comps))
155157

156158
keptLeaves := maps.Keys(leaves)
157159
sort.Strings(keptLeaves)

sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/TestStreamTranslation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ static <T> RunnerApi.TestStreamPayload.Event eventToProto(
123123
.setTimestamp(element.getTimestamp().getMillis())
124124
.setEncodedElement(
125125
ByteString.copyFrom(
126-
CoderUtils.encodeToByteArray(coder, element.getValue()))));
126+
CoderUtils.encodeToByteArray(
127+
coder, element.getValue(), Coder.Context.NESTED))));
127128
}
128129
return RunnerApi.TestStreamPayload.Event.newBuilder().setElementEvent(builder).build();
129130
default:
@@ -149,7 +150,8 @@ static <T> TestStream.Event<T> eventFromProto(
149150
protoEvent.getElementEvent().getElementsList()) {
150151
decodedElements.add(
151152
TimestampedValue.of(
152-
CoderUtils.decodeFromByteArray(coder, element.getEncodedElement().toByteArray()),
153+
CoderUtils.decodeFromByteArray(
154+
coder, element.getEncodedElement().toByteArray(), Coder.Context.NESTED),
153155
new Instant(element.getTimestamp())));
154156
}
155157
return TestStream.ElementEvent.add(decodedElements);

0 commit comments

Comments
 (0)