Ejemplo n.º 1
0
func (c *conn) dial() error {
	var err error
	if c.Protocol == "" {
		c.vtgateConn, err = vtgateconn.Dial(context.Background(), c.Address, c.Timeout)
	} else {
		c.vtgateConn, err = vtgateconn.DialProtocol(context.Background(), c.Protocol, c.Address, c.Timeout)
	}
	return err
}
Ejemplo n.º 2
0
func TestVitess(t *testing.T) {
	topology := &vttestpb.VTTestTopology{
		Keyspaces: []*vttestpb.Keyspace{
			{
				Name: "test_keyspace",
				Shards: []*vttestpb.Shard{
					{
						Name: "0",
					},
				},
			},
		},
	}

	hdl, err := LaunchVitess(ProtoTopo(topology))
	if err != nil {
		t.Error(err)
		return
	}
	defer func() {
		err = hdl.TearDown()
		if err != nil {
			t.Error(err)
			return
		}
	}()
	if hdl.Data == nil {
		t.Error("map is nil")
		return
	}
	portName := "port"
	if vtgateProtocol() == "grpc" {
		portName = "grpc_port"
	}
	fport, ok := hdl.Data[portName]
	if !ok {
		t.Errorf("port %v not found in map", portName)
		return
	}
	port := int(fport.(float64))
	ctx := context.Background()
	conn, err := vtgateconn.DialProtocol(ctx, vtgateProtocol(), fmt.Sprintf("localhost:%d", port), 5*time.Second, "")
	if err != nil {
		t.Error(err)
		return
	}
	_, err = conn.ExecuteShards(ctx, "select 1 from dual", "test_keyspace", []string{"0"}, nil, topodatapb.TabletType_MASTER, nil)
	if err != nil {
		t.Error(err)
		return
	}
}
Ejemplo n.º 3
0
// TestGoClient runs the test suite for the provided client
func TestGoClient(t *testing.T, protocol, addr string) {
	// Create a client connecting to the server
	ctx := context.Background()
	conn, err := vtgateconn.DialProtocol(ctx, protocol, addr, 30*time.Second)
	if err != nil {
		t.Fatalf("dial failed: %v", err)
	}

	testCallerID(t, conn)

	// and clean up
	conn.Close()
}
Ejemplo n.º 4
0
func TestVitess(t *testing.T) {
	hdl, err := LaunchVitess("test_keyspace/0:test_keyspace", "", false)
	if err != nil {
		t.Error(err)
		return
	}
	defer func() {
		err = hdl.TearDown()
		if err != nil {
			t.Error(err)
			return
		}
	}()
	if hdl.Data == nil {
		t.Error("map is nil")
		return
	}
	portName := "port"
	if vtgateProtocol() == "grpc" {
		portName = "grpc_port"
	}
	fport, ok := hdl.Data[portName]
	if !ok {
		t.Errorf("port %v not found in map", portName)
		return
	}
	port := int(fport.(float64))
	ctx := context.Background()
	conn, err := vtgateconn.DialProtocol(ctx, vtgateProtocol(), fmt.Sprintf("localhost:%d", port), 5*time.Second)
	if err != nil {
		t.Error(err)
		return
	}
	_, err = conn.ExecuteShards(ctx, "select 1 from dual", "test_keyspace", []string{"0"}, nil, topodata.TabletType_MASTER)
	if err != nil {
		t.Error(err)
		return
	}
}
Ejemplo n.º 5
0
// TestSuite runs all the tests
func TestSuite(t *testing.T, impl vtgateconn.Impl, fakeServer vtgateservice.VTGateService) {
	vtgateconn.RegisterDialer("test", func(ctx context.Context, address string, timeout time.Duration) (vtgateconn.Impl, error) {
		return impl, nil
	})
	conn, _ := vtgateconn.DialProtocol(context.Background(), "test", "", 0)

	testExecute(t, conn)
	testExecuteShard(t, conn)
	testExecuteKeyspaceIds(t, conn)
	testExecuteKeyRanges(t, conn)
	testExecuteEntityIds(t, conn)
	testExecuteBatchShard(t, conn)
	testExecuteBatchKeyspaceIds(t, conn)
	testStreamExecute(t, conn)
	testStreamExecuteShard(t, conn)
	testStreamExecuteKeyRanges(t, conn)
	testStreamExecuteKeyspaceIds(t, conn)
	testTxPass(t, conn)
	testTxPassNotInTransaction(t, conn)
	testTxFail(t, conn)
	testSplitQuery(t, conn)

	// force a panic at every call, then test that works
	fakeServer.(*fakeVTGateService).panics = true
	testExecutePanic(t, conn)
	testExecuteShardPanic(t, conn)
	testExecuteKeyspaceIdsPanic(t, conn)
	testExecuteKeyRangesPanic(t, conn)
	testExecuteEntityIdsPanic(t, conn)
	testExecuteBatchShardPanic(t, conn)
	testExecuteBatchKeyspaceIdsPanic(t, conn)
	testStreamExecutePanic(t, conn)
	testStreamExecuteShardPanic(t, conn)
	testStreamExecuteKeyRangesPanic(t, conn)
	testStreamExecuteKeyspaceIdsPanic(t, conn)
	testBeginPanic(t, conn)
	testSplitQueryPanic(t, conn)
}