parent
4be37f35ea
commit
6eca934fba
@ -1,41 +1,125 @@ |
||||
package hal |
||||
|
||||
import ( |
||||
"context" |
||||
"github.com/stretchr/testify/assert" |
||||
"testing" |
||||
) |
||||
|
||||
func TestCluster_Run(t *testing.T) { |
||||
var mapping ModuleMapping |
||||
// func TestCluster_Run(t *testing.T) {
|
||||
// var mapping ModuleMapping
|
||||
//
|
||||
// firstModule := &Module{
|
||||
// programStorage: map[int64]*ProgrammedInstruction{
|
||||
// 1: {
|
||||
// Instruction: InstructionStart,
|
||||
// },
|
||||
// },
|
||||
// register: []float64{0},
|
||||
// IO: map[int64]IO{},
|
||||
// }
|
||||
// secondModule := &Module{
|
||||
// programStorage: map[int64]*ProgrammedInstruction{
|
||||
// 1: {
|
||||
// Instruction: InstructionStop,
|
||||
// },
|
||||
// },
|
||||
// register: []float64{0},
|
||||
// IO: map[int64]IO{},
|
||||
// }
|
||||
//
|
||||
// mapping = map[MultiThreadedIOPort]MultiThreadedIOPort{
|
||||
// {
|
||||
// Module: firstModule,
|
||||
// IOPort: 0,
|
||||
// }: {
|
||||
// Module: secondModule,
|
||||
// IOPort: 0,
|
||||
// },
|
||||
// }
|
||||
// assert.NoError(t, mapping.BuildCluster().Run(context.Background()))
|
||||
// }
|
||||
|
||||
firstModule := &Module{ |
||||
programStorage: map[int64]*ProgrammedInstruction{ |
||||
1: { |
||||
Instruction: InstructionStart, |
||||
func TestModuleMapping_BuildCluster(t *testing.T) { |
||||
config := &ClusterConfig{ |
||||
Nodes: []*ClusterNode{ |
||||
{ |
||||
Name: "node1", |
||||
}, |
||||
{ |
||||
Name: "node2", |
||||
}, |
||||
{ |
||||
Name: "node3", |
||||
}, |
||||
}, |
||||
register: []float64{0}, |
||||
IO: map[int64]IO{}, |
||||
} |
||||
secondModule := &Module{ |
||||
programStorage: map[int64]*ProgrammedInstruction{ |
||||
1: { |
||||
Instruction: InstructionStop, |
||||
Connections: []*ClusterConnection{ |
||||
{ |
||||
SourceNode: "node1", |
||||
SourcePort: 1, |
||||
DestNode: "node2", |
||||
DestPort: 1, |
||||
}, |
||||
{ |
||||
SourceNode: "node1", |
||||
SourcePort: 2, |
||||
DestNode: "node2", |
||||
DestPort: 2, |
||||
}, |
||||
{ |
||||
SourceNode: "node2", |
||||
SourcePort: 3, |
||||
DestNode: "node3", |
||||
DestPort: 2, |
||||
}, |
||||
{ |
||||
SourceNode: "node1", |
||||
SourcePort: 3, |
||||
DestNode: "node3", |
||||
DestPort: 3, |
||||
}, |
||||
}, |
||||
register: []float64{0}, |
||||
IO: map[int64]IO{}, |
||||
} |
||||
|
||||
mapping = map[MultiThreadedIOPort]MultiThreadedIOPort{ |
||||
{ |
||||
Module: firstModule, |
||||
IOPort: 0, |
||||
}: { |
||||
Module: secondModule, |
||||
IOPort: 0, |
||||
modules := make(map[string]*Module) |
||||
modules = map[string]*Module{ |
||||
"node1": { |
||||
programStorage: map[int64]*ProgrammedInstruction{ |
||||
1: {Instruction: InstructionStart}, |
||||
2: {Instruction: InstructionStop}, |
||||
}, |
||||
register: []float64{0}, |
||||
IO: map[int64]IO{}, |
||||
}, |
||||
"node2": { |
||||
programStorage: map[int64]*ProgrammedInstruction{ |
||||
1: {Instruction: InstructionStart}, |
||||
2: {Instruction: InstructionStop}, |
||||
}, |
||||
register: []float64{0}, |
||||
IO: map[int64]IO{}, |
||||
}, |
||||
"node3": { |
||||
programStorage: map[int64]*ProgrammedInstruction{ |
||||
1: {Instruction: InstructionStart}, |
||||
2: {Instruction: InstructionStop}, |
||||
}, |
||||
register: []float64{0}, |
||||
IO: map[int64]IO{}, |
||||
}, |
||||
} |
||||
assert.NoError(t, mapping.BuildCluster().Run(context.Background())) |
||||
|
||||
cluster, err := config.BuildCluster(modules) |
||||
assert.NoError(t, err) |
||||
// First connection config
|
||||
assert.NotNil(t, cluster.modules[0].IO[1]) |
||||
assert.NotNil(t, cluster.modules[1].IO[1]) |
||||
// Second
|
||||
assert.NotNil(t, cluster.modules[0].IO[2]) |
||||
assert.NotNil(t, cluster.modules[1].IO[2]) |
||||
// Third
|
||||
assert.NotNil(t, cluster.modules[1].IO[3]) |
||||
assert.NotNil(t, cluster.modules[2].IO[2]) |
||||
// Fourth
|
||||
assert.NotNil(t, cluster.modules[0].IO[3]) |
||||
assert.NotNil(t, cluster.modules[2].IO[3]) |
||||
} |
||||
|
Loading…
Reference in new issue