Commit a22c8d74 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8d420d23
...@@ -213,6 +213,20 @@ func (t *tCluster) registerNewNode(name string) *tNode { ...@@ -213,6 +213,20 @@ func (t *tCluster) registerNewNode(name string) *tNode {
return node return node
} }
// getNode returns node by name.
//
// The node must be registered before with registerNewNode.
func (t *tCluster) getNode(name string) *tNode {
t.tabMu.Lock()
defer t.tabMu.Unlock()
tnode, ok := t.nodeTab[name]
if !ok {
t.Fatalf("no node %q", name)
}
return tnode
}
// NewMaster creates new master on node name. // NewMaster creates new master on node name.
// //
...@@ -236,40 +250,52 @@ func (t *tCluster) NewMaster(name string) ITestMaster { ...@@ -236,40 +250,52 @@ func (t *tCluster) NewMaster(name string) ITestMaster {
// Master returns master node that was previouslt created via NewMaster(name). // Master returns master node that was previouslt created via NewMaster(name).
func (t *tCluster) Master(name string) ITestMaster { func (t *tCluster) Master(name string) ITestMaster {
t.tabMu.Lock() tnode := t.getNode(name)
defer t.tabMu.Unlock()
tnode, ok := t.nodeTab[name]
if !ok {
t.Fatalf("no node %q", name)
}
m, ok := tnode.itest.(ITestMaster) m, ok := tnode.itest.(ITestMaster)
if !ok { if !ok {
t.Fatalf("node %q if of type %T, not master", name, tnode.itest) t.Fatalf("node %q is of type %T, not master", name, tnode.itest)
} }
return m return m
} }
// {New,}Storage are similar to {New,}Master but for storage nodes.
func (t *tCluster) NewStorage(name, masterAddr string, back storage.Backend) ITestStorage { func (t *tCluster) NewStorage(name, masterAddr string, back storage.Backend) ITestStorage {
node := t.registerNewNode(name) tnode := t.registerNewNode(name)
s := tNewStorage(t.name, masterAddr, ":1", node.net, back) s := tNewStorage(t.name, masterAddr, ":1", tnode.net, back)
t.gotracer.RegisterNode(s.node, name) t.gotracer.RegisterNode(s.node, name)
t.runWG.Go(func(ctx context.Context) error { t.runWG.Go(func(ctx context.Context) error {
return s.Run(ctx) return s.Run(ctx)
}) })
return s return s
} }
func (t *tCluster) Storage(name string) ITestStorage {
tnode := t.getNode(name)
s, ok := tnode.itest.(ITestStorage)
if !ok {
t.Fatalf("node %q is of type %T, not storage", name, tnode.itest)
}
return s
}
// {New,}Client are similar to {New,}Master but for client nodes.
func (t *tCluster) NewClient(name, masterAddr string) ITestClient { func (t *tCluster) NewClient(name, masterAddr string) ITestClient {
node := t.registerNewNode(name) tnode := t.registerNewNode(name)
c := NewClient(t.name, masterAddr, node.net) c := NewClient(t.name, masterAddr, tnode.net)
t.gotracer.RegisterNode(c.node, name) t.gotracer.RegisterNode(c.node, name)
t.runWG.Go(func(ctx context.Context) error { t.runWG.Go(func(ctx context.Context) error {
return c.Run(ctx) return c.Run(ctx)
}) })
return c return c
} }
func (t *tCluster) Client(name string) ITestClient {
tnode := t.getNode(name)
c, ok := tnode.itest.(ITestClient)
if !ok {
t.Fatalf("node %q is of type %T, not client", name, tnode.itest)
}
return c
}
// tStorage is test-wrapper around Storage. // tStorage is test-wrapper around Storage.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment