@@ -26,6 +26,10 @@ import (
26
26
"encoding/json"
27
27
"errors"
28
28
"fmt"
29
+ "io"
30
+ "math"
31
+ "os"
32
+
29
33
"github.com/golang/mock/gomock"
30
34
"github.com/opentracing/opentracing-go"
31
35
"github.com/pborman/uuid"
@@ -37,8 +41,6 @@ import (
37
41
"go.uber.org/cadence/internal/common/backoff"
38
42
"go.uber.org/cadence/internal/common/serializer"
39
43
"go.uber.org/zap"
40
- "io/ioutil"
41
- "math"
42
44
)
43
45
44
46
const (
@@ -133,19 +135,12 @@ func (r *WorkflowReplayer) ReplayWorkflowHistory(logger *zap.Logger, history *sh
133
135
return r .replayWorkflowHistory (logger , service , replayDomainName , nil , history , nil )
134
136
}
135
137
136
- // ReplayWorkflowHistoryFromJSONFile executes a single decision task for the given json history file.
137
- // Use for testing the backwards compatibility of code changes and troubleshooting workflows in a debugger.
138
- // The logger is an optional parameter. Defaults to the noop logger.
139
- func (r * WorkflowReplayer ) ReplayWorkflowHistoryFromJSONFile (logger * zap.Logger , jsonfileName string ) error {
140
- return r .ReplayPartialWorkflowHistoryFromJSONFile (logger , jsonfileName , 0 )
138
+ func (r * WorkflowReplayer ) ReplayWorkflowHistoryFromJSON (logger * zap.Logger , reader io.Reader ) error {
139
+ return r .ReplayPartialWorkflowHistoryFromJSON (logger , reader , 0 )
141
140
}
142
141
143
- // ReplayPartialWorkflowHistoryFromJSONFile executes a single decision task for the given json history file up to provided
144
- // lastEventID(inclusive).
145
- // Use for testing backwards compatibility of code changes and troubleshooting workflows in a debugger.
146
- // The logger is an optional parameter. Defaults to the noop logger.
147
- func (r * WorkflowReplayer ) ReplayPartialWorkflowHistoryFromJSONFile (logger * zap.Logger , jsonfileName string , lastEventID int64 ) error {
148
- history , err := extractHistoryFromFile (jsonfileName , lastEventID )
142
+ func (r * WorkflowReplayer ) ReplayPartialWorkflowHistoryFromJSON (logger * zap.Logger , reader io.Reader , lastEventID int64 ) error {
143
+ history , err := extractHistoryFromReader (reader , lastEventID )
149
144
150
145
if err != nil {
151
146
return err
@@ -162,6 +157,28 @@ func (r *WorkflowReplayer) ReplayPartialWorkflowHistoryFromJSONFile(logger *zap.
162
157
return r .replayWorkflowHistory (logger , service , replayDomainName , nil , history , nil )
163
158
}
164
159
160
+ // ReplayWorkflowHistoryFromJSONFile executes a single decision task for the given json history file.
161
+ // Use for testing the backwards compatibility of code changes and troubleshooting workflows in a debugger.
162
+ // The logger is an optional parameter. Defaults to the noop logger.
163
+ func (r * WorkflowReplayer ) ReplayWorkflowHistoryFromJSONFile (logger * zap.Logger , jsonfileName string ) error {
164
+ return r .ReplayPartialWorkflowHistoryFromJSONFile (logger , jsonfileName , 0 )
165
+ }
166
+
167
+ // ReplayPartialWorkflowHistoryFromJSONFile executes a single decision task for the given json history file up to provided
168
+ // lastEventID(inclusive).
169
+ // Use for testing backwards compatibility of code changes and troubleshooting workflows in a debugger.
170
+ // The logger is an optional parameter. Defaults to the noop logger.
171
+ func (r * WorkflowReplayer ) ReplayPartialWorkflowHistoryFromJSONFile (logger * zap.Logger , jsonfileName string , lastEventID int64 ) error {
172
+ file , err := os .Open (jsonfileName )
173
+ if err != nil {
174
+ return fmt .Errorf ("could not open file: %w" , err )
175
+ }
176
+ defer func () {
177
+ _ = file .Close ()
178
+ }()
179
+ return r .ReplayPartialWorkflowHistoryFromJSON (logger , file , lastEventID )
180
+ }
181
+
165
182
// ReplayWorkflowExecution replays workflow execution loading it from Cadence service.
166
183
// The logger is an optional parameter. Defaults to the noop logger.
167
184
func (r * WorkflowReplayer ) ReplayWorkflowExecution (
@@ -336,17 +353,17 @@ func (r *WorkflowReplayer) replayWorkflowHistory(
336
353
return fmt .Errorf ("replay workflow doesn't return the same result as the last event, resp: %v, last: %v" , resp , last )
337
354
}
338
355
339
- func extractHistoryFromFile ( jsonfileName string , lastEventID int64 ) (* shared.History , error ) {
340
- raw , err := ioutil . ReadFile ( jsonfileName )
356
+ func extractHistoryFromReader ( r io. Reader , lastEventID int64 ) (* shared.History , error ) {
357
+ raw , err := io . ReadAll ( r )
341
358
if err != nil {
342
- return nil , err
359
+ return nil , fmt . Errorf ( "failed to read data: %w" , err )
343
360
}
344
361
345
362
var deserializedEvents []* shared.HistoryEvent
346
363
err = json .Unmarshal (raw , & deserializedEvents )
347
364
348
365
if err != nil {
349
- return nil , err
366
+ return nil , fmt . Errorf ( "invalid json contents: %w" , err )
350
367
}
351
368
352
369
if lastEventID <= 0 {
0 commit comments