Skip to content

Commit

Permalink
rename setupDatabase to setupNode
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed Jun 25, 2024
1 parent 495d931 commit e54c1ac
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 77 deletions.
2 changes: 1 addition & 1 deletion internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (db *db) NewConcurrentTxn(ctx context.Context, readonly bool) (datastore.Tx
return datastore.NewConcurrentTxnFrom(ctx, db.rootstore, txnId, readonly)
}

// Root returns the root datastore.
// Rootstore returns the root datastore.
func (db *db) Rootstore() datastore.Rootstore {
return db.rootstore
}
Expand Down
115 changes: 47 additions & 68 deletions internal/db/p2p_replicator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ func TestSetReplicator_WithValidCollection_ShouldSucceed(t *testing.T) {
Schemas: []string{"User"},
})
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peer.ID("other"), replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas)
break
}
msg := <-sub.Message()
replicator := msg.Data.(event.Replicator)
require.Equal(t, peer.ID("other"), replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas)
}

func TestSetReplicator_WithValidCollectionsOnSeparateSet_ShouldSucceed(t *testing.T) {
Expand All @@ -120,12 +118,10 @@ func TestSetReplicator_WithValidCollectionsOnSeparateSet_ShouldSucceed(t *testin
Schemas: []string{"User"},
})
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema1.Root: {}}, replicator.Schemas)
break
}
msg := <-sub.Message()
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema1.Root: {}}, replicator.Schemas)

cols2, err := db.AddSchema(ctx, `type Book { name: String }`)
require.NoError(t, err)
Expand All @@ -136,12 +132,10 @@ func TestSetReplicator_WithValidCollectionsOnSeparateSet_ShouldSucceed(t *testin
Schemas: []string{"Book"},
})
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema1.Root: {}, schema2.Root: {}}, replicator.Schemas)
break
}
msg = <-sub.Message()
replicator = msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema1.Root: {}, schema2.Root: {}}, replicator.Schemas)
}

func TestSetReplicator_WithValidCollectionWithDoc_ShouldSucceed(t *testing.T) {
Expand All @@ -165,14 +159,12 @@ func TestSetReplicator_WithValidCollectionWithDoc_ShouldSucceed(t *testing.T) {
Schemas: []string{"User"},
})
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peer.ID("other"), replicator.Info.ID)
require.Equal(t, map[string]struct{}{col.SchemaRoot(): {}}, replicator.Schemas)
for docEvt := range replicator.Docs {
require.Equal(t, doc.ID().String(), docEvt.DocID)
}
break
msg := <-sub.Message()
replicator := msg.Data.(event.Replicator)
require.Equal(t, peer.ID("other"), replicator.Info.ID)
require.Equal(t, map[string]struct{}{col.SchemaRoot(): {}}, replicator.Schemas)
for docEvt := range replicator.Docs {
require.Equal(t, doc.ID().String(), docEvt.DocID)
}
}

Expand Down Expand Up @@ -214,20 +206,16 @@ func TestDeleteReplicator_WithValidCollection_ShouldSucceed(t *testing.T) {
Schemas: []string{"User"},
})
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas)
break
}
msg := <-sub.Message()
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas)
err = db.DeleteReplicator(ctx, client.Replicator{Info: peer.AddrInfo{ID: peerID}})
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{}, replicator.Schemas)
break
}
msg = <-sub.Message()
replicator = msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{}, replicator.Schemas)
}

func TestDeleteReplicator_PartialWithValidCollections_ShouldSucceed(t *testing.T) {
Expand All @@ -254,20 +242,17 @@ func TestDeleteReplicator_PartialWithValidCollections_ShouldSucceed(t *testing.T
Schemas: []string{"User", "Book"},
})
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema1.Root: {}, schema2.Root: {}}, replicator.Schemas)
break
}
msg := <-sub.Message()
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema1.Root: {}, schema2.Root: {}}, replicator.Schemas)

err = db.DeleteReplicator(ctx, client.Replicator{Info: peer.AddrInfo{ID: peerID}, Schemas: []string{"User"}})
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema2.Root: {}}, replicator.Schemas)
break
}
msg = <-sub.Message()
replicator = msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema2.Root: {}}, replicator.Schemas)
}

func TestGetAllReplicators_WithValidCollection_ShouldSucceed(t *testing.T) {
Expand All @@ -290,12 +275,10 @@ func TestGetAllReplicators_WithValidCollection_ShouldSucceed(t *testing.T) {
Schemas: []string{"User"},
})
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas)
break
}
msg := <-sub.Message()
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas)

reps, err := db.GetAllReplicators(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -323,19 +306,15 @@ func TestLoadReplicators_WithValidCollection_ShouldSucceed(t *testing.T) {
Schemas: []string{"User"},
})
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas)
break
}
msg := <-sub.Message()
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas)

err = db.loadAndPublishReplicators(ctx)
require.NoError(t, err)
for msg := range sub.Message() {
replicator := msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas)
break
}
msg = <-sub.Message()
replicator = msg.Data.(event.Replicator)
require.Equal(t, peerID, replicator.Info.ID)
require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas)
}
1 change: 0 additions & 1 deletion internal/db/p2p_schema_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ func TestLoadP2PCollection_WithValidCollectionsAndDocs_ShouldSucceed(t *testing.
msg = <-sub.Message()
p2pTopic = msg.Data.(event.P2PTopic)
require.Equal(t, []string{doc2.ID().String()}, p2pTopic.ToAdd)

}

func TestGetAllP2PCollections_WithMultipleValidCollections_ShouldSucceed(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/bench_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func NewTestDB(ctx context.Context, t testing.TB) (client.DB, error) {

func NewTestStorage(ctx context.Context, t testing.TB) (ds.Batching, error) {
dbi, err := newBenchStoreInfo(ctx, t)
return dbi.Root(), err
return dbi.Rootstore(), err
}

func newBenchStoreInfo(ctx context.Context, t testing.TB) (client.DB, error) {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ func NewBadgerFileDB(ctx context.Context, t testing.TB) (client.DB, error) {
return node.DB, err
}

// setupDatabase returns the database implementation for the current
// setupNode returns the database implementation for the current
// testing state. The database type on the test state is used to
// select the datastore implementation to use.
func setupDatabase(s *state) (*node.Node, string, error) {
func setupNode(s *state) (*node.Node, string, error) {
opts := []node.Option{
node.WithLensPoolSize(lensPoolSize),
// The test framework sets this up elsewhere when required so that it may be wrapped
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/utils2.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,10 @@ func setStartingNodes(

// If nodes have not been explicitly configured via actions, setup a default one.
if !hasExplicitNode {
db, path, err := setupDatabase(s)
node, path, err := setupNode(s)
require.Nil(s.t, err)

c, err := setupClient(s, db)
c, err := setupClient(s, node)
require.Nil(s.t, err)

s.nodes = append(s.nodes, c)
Expand All @@ -673,7 +673,7 @@ func restartNodes(
for i := len(s.nodes) - 1; i >= 0; i-- {
originalPath := databaseDir
databaseDir = s.dbPaths[i]
node, _, err := setupDatabase(s)
node, _, err := setupNode(s)
require.Nil(s.t, err)
databaseDir = originalPath

Expand Down Expand Up @@ -787,7 +787,7 @@ func configureNode(
return
}

node, path, err := setupDatabase(s) //disable change dector, or allow it?
node, path, err := setupNode(s) //disable change dector, or allow it?
require.NoError(s.t, err)

privateKey, err := crypto.GenerateEd25519()
Expand Down

0 comments on commit e54c1ac

Please sign in to comment.