parent
4be37f35ea
commit
6eca934fba
@ -1,41 +1,125 @@ |
|||||||
package hal |
package hal |
||||||
|
|
||||||
import ( |
import ( |
||||||
"context" |
|
||||||
"github.com/stretchr/testify/assert" |
"github.com/stretchr/testify/assert" |
||||||
"testing" |
"testing" |
||||||
) |
) |
||||||
|
|
||||||
func TestCluster_Run(t *testing.T) { |
// func TestCluster_Run(t *testing.T) {
|
||||||
var mapping ModuleMapping |
// 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{ |
func TestModuleMapping_BuildCluster(t *testing.T) { |
||||||
programStorage: map[int64]*ProgrammedInstruction{ |
config := &ClusterConfig{ |
||||||
1: { |
Nodes: []*ClusterNode{ |
||||||
Instruction: InstructionStart, |
{ |
||||||
|
Name: "node1", |
||||||
|
}, |
||||||
|
{ |
||||||
|
Name: "node2", |
||||||
|
}, |
||||||
|
{ |
||||||
|
Name: "node3", |
||||||
}, |
}, |
||||||
}, |
}, |
||||||
register: []float64{0}, |
Connections: []*ClusterConnection{ |
||||||
IO: map[int64]IO{}, |
{ |
||||||
} |
SourceNode: "node1", |
||||||
secondModule := &Module{ |
SourcePort: 1, |
||||||
programStorage: map[int64]*ProgrammedInstruction{ |
DestNode: "node2", |
||||||
1: { |
DestPort: 1, |
||||||
Instruction: InstructionStop, |
}, |
||||||
|
{ |
||||||
|
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{ |
modules := make(map[string]*Module) |
||||||
{ |
modules = map[string]*Module{ |
||||||
Module: firstModule, |
"node1": { |
||||||
IOPort: 0, |
programStorage: map[int64]*ProgrammedInstruction{ |
||||||
}: { |
1: {Instruction: InstructionStart}, |
||||||
Module: secondModule, |
2: {Instruction: InstructionStop}, |
||||||
IOPort: 0, |
}, |
||||||
|
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