Example #1
0
func newCluster(tb testing.TB, discoveryClient discovery.Client, servers map[string]*grpc.Server) Cluster {
	cluster := cluster{
		rolers:  make(map[string]role.Roler),
		servers: make(map[string]server.CombinedAPIServer),
		addresser: route.NewDiscoveryAddresser(
			discoveryClient,
			testNamespace(),
		),
		sharder: route.NewSharder(
			testShardsPerServer * testNumServers,
		),
		tb: tb,
	}
	for address, s := range servers {
		combinedAPIServer := server.NewCombinedAPIServer(
			cluster.sharder,
			route.NewRouter(
				cluster.addresser,
				grpcutil.NewDialer(
					grpc.WithInsecure(),
				),
				address,
			),
			getDriver(tb, address),
		)
		pfs.RegisterApiServer(s, combinedAPIServer)
		pfs.RegisterInternalApiServer(s, combinedAPIServer)
		roler := role.NewRoler(cluster.addresser, cluster.sharder, combinedAPIServer, address, testNumReplicas)
		go func() { require.Equal(tb, roler.Run(), discovery.ErrCancelled) }()
		cluster.addresses = append(cluster.addresses, address)
		cluster.rolers[address] = roler
		cluster.servers[address] = combinedAPIServer
	}
	return &cluster
}
Example #2
0
func (c *cluster) Restart(server int) {
	c.rolers[c.addresses[server]] = role.NewRoler(c.addresser, c.sharder, c.servers[c.addresses[server]], c.addresses[server], testNumReplicas)
	go func() { require.Equal(c.tb, c.rolers[c.addresses[server]].Run(), discovery.ErrCancelled) }()
}