-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (32 loc) · 804 Bytes
/
main.go
File metadata and controls
42 lines (32 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"strconv"
"github.com/rodrigocitadin/two-phase-commit/internal"
)
const (
numberOfNodes = 4
)
func main() {
nodeAddresses := make(map[int]string, numberOfNodes)
for i := range numberOfNodes {
port := 3000 + i
nodeAddresses[i] = "localhost:" + strconv.Itoa(port)
}
nodes := make([]internal.Node, 0, numberOfNodes)
for i := range numberOfNodes {
node, err := internal.NewNode(i, nodeAddresses)
if err != nil {
panic(err)
}
nodes = append(nodes, node)
}
nodes[0].Transaction(1)
fmt.Println("\n--- end of transaction ---\n")
nodes[1].Transaction(1)
fmt.Println("\n--- end of transaction ---\n")
nodes[3].Transaction(1)
fmt.Println("\n--- end of transaction ---\n")
nodes[2].Transaction(1)
fmt.Println("\n--- end of transaction ---\n")
}