@@ -26,8 +26,9 @@ import (
26
26
"encoding/json"
27
27
"errors"
28
28
"fmt"
29
- "io/ioutil "
29
+ "io"
30
30
"math"
31
+ "os"
31
32
32
33
"github.com/golang/mock/gomock"
33
34
"github.com/opentracing/opentracing-go"
@@ -120,6 +121,16 @@ func (r *WorkflowReplayer) RegisterWorkflowWithOptions(w interface{}, options Re
120
121
r .registry .RegisterWorkflowWithOptions (w , options )
121
122
}
122
123
124
+ // RegisterActivity registers an activity function for this replayer
125
+ func (r * WorkflowReplayer ) RegisterActivity (a interface {}) {
126
+ r .registry .RegisterActivity (a )
127
+ }
128
+
129
+ // RegisterActivityWithOptions registers an activity function for this replayer with custom options, e.g. an explicit name.
130
+ func (r * WorkflowReplayer ) RegisterActivityWithOptions (a interface {}, options RegisterActivityOptions ) {
131
+ r .registry .RegisterActivityWithOptions (a , options )
132
+ }
133
+
123
134
// ReplayWorkflowHistory executes a single decision task for the given history.
124
135
// Use for testing backwards compatibility of code changes and troubleshooting workflows in a debugger.
125
136
// The logger is an optional parameter. Defaults to the noop logger.
@@ -135,19 +146,12 @@ func (r *WorkflowReplayer) ReplayWorkflowHistory(logger *zap.Logger, history *sh
135
146
return r .replayWorkflowHistory (logger , service , replayDomainName , nil , history , nil )
136
147
}
137
148
138
- // ReplayWorkflowHistoryFromJSONFile executes a single decision task for the given json history file.
139
- // Use for testing the backwards compatibility of code changes and troubleshooting workflows in a debugger.
140
- // The logger is an optional parameter. Defaults to the noop logger.
141
- func (r * WorkflowReplayer ) ReplayWorkflowHistoryFromJSONFile (logger * zap.Logger , jsonfileName string ) error {
142
- return r .ReplayPartialWorkflowHistoryFromJSONFile (logger , jsonfileName , 0 )
149
+ func (r * WorkflowReplayer ) ReplayWorkflowHistoryFromJSON (logger * zap.Logger , reader io.Reader ) error {
150
+ return r .ReplayPartialWorkflowHistoryFromJSON (logger , reader , 0 )
143
151
}
144
152
145
- // ReplayPartialWorkflowHistoryFromJSONFile executes a single decision task for the given json history file up to provided
146
- // lastEventID(inclusive).
147
- // Use for testing backwards compatibility of code changes and troubleshooting workflows in a debugger.
148
- // The logger is an optional parameter. Defaults to the noop logger.
149
- func (r * WorkflowReplayer ) ReplayPartialWorkflowHistoryFromJSONFile (logger * zap.Logger , jsonfileName string , lastEventID int64 ) error {
150
- history , err := extractHistoryFromFile (jsonfileName , lastEventID )
153
+ func (r * WorkflowReplayer ) ReplayPartialWorkflowHistoryFromJSON (logger * zap.Logger , reader io.Reader , lastEventID int64 ) error {
154
+ history , err := extractHistoryFromReader (reader , lastEventID )
151
155
152
156
if err != nil {
153
157
return err
@@ -164,6 +168,28 @@ func (r *WorkflowReplayer) ReplayPartialWorkflowHistoryFromJSONFile(logger *zap.
164
168
return r .replayWorkflowHistory (logger , service , replayDomainName , nil , history , nil )
165
169
}
166
170
171
+ // ReplayWorkflowHistoryFromJSONFile executes a single decision task for the given json history file.
172
+ // Use for testing the backwards compatibility of code changes and troubleshooting workflows in a debugger.
173
+ // The logger is an optional parameter. Defaults to the noop logger.
174
+ func (r * WorkflowReplayer ) ReplayWorkflowHistoryFromJSONFile (logger * zap.Logger , jsonfileName string ) error {
175
+ return r .ReplayPartialWorkflowHistoryFromJSONFile (logger , jsonfileName , 0 )
176
+ }
177
+
178
+ // ReplayPartialWorkflowHistoryFromJSONFile executes a single decision task for the given json history file up to provided
179
+ // lastEventID(inclusive).
180
+ // Use for testing backwards compatibility of code changes and troubleshooting workflows in a debugger.
181
+ // The logger is an optional parameter. Defaults to the noop logger.
182
+ func (r * WorkflowReplayer ) ReplayPartialWorkflowHistoryFromJSONFile (logger * zap.Logger , jsonfileName string , lastEventID int64 ) error {
183
+ file , err := os .Open (jsonfileName )
184
+ if err != nil {
185
+ return fmt .Errorf ("could not open file: %w" , err )
186
+ }
187
+ defer func () {
188
+ _ = file .Close ()
189
+ }()
190
+ return r .ReplayPartialWorkflowHistoryFromJSON (logger , file , lastEventID )
191
+ }
192
+
167
193
// ReplayWorkflowExecution replays workflow execution loading it from Cadence service.
168
194
// The logger is an optional parameter. Defaults to the noop logger.
169
195
func (r * WorkflowReplayer ) ReplayWorkflowExecution (
@@ -338,17 +364,17 @@ func (r *WorkflowReplayer) replayWorkflowHistory(
338
364
return fmt .Errorf ("replay workflow doesn't return the same result as the last event, resp: %v, last: %v" , resp , last )
339
365
}
340
366
341
- func extractHistoryFromFile ( jsonfileName string , lastEventID int64 ) (* shared.History , error ) {
342
- raw , err := ioutil . ReadFile ( jsonfileName )
367
+ func extractHistoryFromReader ( r io. Reader , lastEventID int64 ) (* shared.History , error ) {
368
+ raw , err := io . ReadAll ( r )
343
369
if err != nil {
344
- return nil , err
370
+ return nil , fmt . Errorf ( "failed to read data: %w" , err )
345
371
}
346
372
347
373
var deserializedEvents []* shared.HistoryEvent
348
374
err = json .Unmarshal (raw , & deserializedEvents )
349
375
350
376
if err != nil {
351
- return nil , err
377
+ return nil , fmt . Errorf ( "invalid json contents: %w" , err )
352
378
}
353
379
354
380
if lastEventID <= 0 {
0 commit comments