Skip to content
Open
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
3 changes: 2 additions & 1 deletion consumer/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package consumer

import (
"context"
"reflect"
"sync"
"time"

Expand Down Expand Up @@ -244,7 +245,7 @@ func servePrimary(s *shard) (err error) {
func waitAndTearDown(s *shard, done func()) {
s.wg.Wait()

if s.store != nil {
if s.store != nil && !reflect.ValueOf(s.store).IsNil() {
s.store.Destroy()
}
done()
Expand Down
13 changes: 13 additions & 0 deletions consumer/shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ func TestShardAppNewStoreError(t *testing.T) {
tf.allocateShard(makeShard(shardA)) // Cleanup.
}

func TestShardAppNilJSONStore(t *testing.T) {
var tf, cleanup = newTestFixture(t)
defer cleanup()

tf.app.nilStore = true
tf.allocateShard(makeShard(shardA), localID)

assert.Equal(t, "completeRecovery: app.NewStore: state must not be nil",
expectStatusCode(t, tf.state, pc.ReplicaStatus_FAILED).Errors[0])

tf.allocateShard(makeShard(shardA)) // Cleanup.
}

func TestShardAppNewMessageFails(t *testing.T) {
var tf, cleanup = newTestFixture(t)
defer cleanup()
Expand Down
5 changes: 4 additions & 1 deletion consumer/store_json_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ var _ Store = &JSONFileStore{} // JSONFileStore is-a Store.

// NewJSONFileStore returns a new JSONFileStore. |state| is the runtime instance
// of the Store's state, which is decoded into, encoded from, and retained
// as JSONFileState.State.
// as JSONFileState.State. |state| must not be nil.
func NewJSONFileStore(rec *recoverylog.Recorder, state interface{}) (*JSONFileStore, error) {
if state == nil {
return nil, errors.New("state must not be nil")
}
var store = &JSONFileStore{
State: state,
fs: recoverylog.RecordedAferoFS{Recorder: rec, Fs: afero.NewOsFs()},
Expand Down
3 changes: 3 additions & 0 deletions consumer/test_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type testApplication struct {
finalizeErr error // Error returned by Application.FinalizeTxn().
startCommitErr error // Error returned by Store.StartCommit().
restoreCheckpointErr error // Error returned by Store.RestoreCheckpoint().
nilStore bool // Whether the application initializes its store in Application.NewStore().
finishedCh chan OpFuture // Signaled on FinishedTxn().
db *sql.DB // "Remote" sqlite database.
}
Expand Down Expand Up @@ -114,6 +115,8 @@ func (a *testApplication) NewStore(shard Shard, rec *recoverylog.Recorder) (Stor
return &errStore{app: a}, nil
} else if rec == nil {
return NewSQLStore(a.db), nil
} else if a.nilStore {
return NewJSONFileStore(rec, nil)
} else {
var state = make(map[string]string)
return NewJSONFileStore(rec, &state)
Expand Down