当前位置: 首页>>代码示例>>Golang>>正文


Golang fakecacheservice.Register函数代码示例

本文整理汇总了Golang中github.com/youtube/vitess/go/vt/tabletserver/fakecacheservice.Register函数的典型用法代码示例。如果您正苦于以下问题:Golang Register函数的具体用法?Golang Register怎么用?Golang Register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Register函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestSchemaInfoDropTable

func TestSchemaInfoDropTable(t *testing.T) {
	fakecacheservice.Register()
	db := fakesqldb.Register()
	for query, result := range getSchemaInfoTestSupportedQueries() {
		db.AddQuery(query, result)
	}
	existingTable := "test_table_01"
	createOrDropTableQuery := fmt.Sprintf("%s and table_name = '%s'", baseShowTables, existingTable)
	db.AddQuery(createOrDropTableQuery, &mproto.QueryResult{
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			createTestTableBaseShowTable(existingTable),
		},
	})
	schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
	appParams := sqldb.ConnParams{}
	dbaParams := sqldb.ConnParams{}
	cachePool := newTestSchemaInfoCachePool(false, schemaInfo.queryServiceStats)
	cachePool.Open()
	defer cachePool.Close()
	schemaInfo.Open(&appParams, &dbaParams, getSchemaInfoTestSchemaOverride(), cachePool, false)
	tableInfo := schemaInfo.GetTable(existingTable)
	if tableInfo == nil {
		t.Fatalf("table: %s should exist", existingTable)
	}
	schemaInfo.DropTable(existingTable)
	tableInfo = schemaInfo.GetTable(existingTable)
	if tableInfo != nil {
		t.Fatalf("table: %s should not exist", existingTable)
	}
	schemaInfo.Close()
}
开发者ID:ruiaylin,项目名称:vitess,代码行数:32,代码来源:schema_info_test.go

示例2: TestCachePoolState

func TestCachePoolState(t *testing.T) {
	fakecacheservice.Register()
	fakesqldb.Register()
	rowCacheConfig := RowCacheConfig{
		Binary:      "ls",
		Connections: 100,
	}
	cachePool := newTestCachePool(rowCacheConfig, true)
	idleTimeout := 1 * time.Second
	cachePool.idleTimeout = idleTimeout
	cachePool.Open()
	cachePool.memcacheStats.update()
	defer cachePool.Close()
	if cachePool.Available() <= 0 {
		t.Fatalf("cache pool should have connections available")
	}
	if cachePool.Capacity() <= 0 {
		t.Fatalf("cache pool should have positive capacity")
	}
	if cachePool.MaxCap() <= 0 {
		t.Fatalf("cache pool should have positive max cap")
	}
	if cachePool.WaitCount() > 0 {
		t.Fatalf("cache pool has never waited for a connection, WaitCount should return 0")
	}
	if cachePool.WaitTime() > 0 {
		t.Fatalf("cache pool has never waited for a connection, WaitTime should return 0")
	}
	if cachePool.IdleTimeout() != idleTimeout {
		t.Fatalf("cache pool's idle timeout does not match the specified one")
	}
	if len(cachePool.StatsJSON()) <= 0 {
		t.Fatalf("cache pool stats json should return non empty result")
	}
}
开发者ID:littleyang,项目名称:vitess,代码行数:35,代码来源:cache_pool_test.go

示例3: TestCachePoolStateWithoutOpen

func TestCachePoolStateWithoutOpen(t *testing.T) {
	fakecacheservice.Register()
	fakesqldb.Register()
	rowCacheConfig := RowCacheConfig{
		Binary:      "ls",
		Connections: 100,
	}
	cachePool := newTestCachePool(rowCacheConfig, false)
	idleTimeout := 1 * time.Second
	cachePool.idleTimeout = idleTimeout
	if cachePool.StatsJSON() != "{}" {
		t.Fatalf("cache pool StatsJSON() should return {}")
	}
	if cachePool.Capacity() != 0 {
		t.Fatalf("cache pool Capacity() should return 0")
	}
	if cachePool.Available() != 0 {
		t.Fatalf("cache pool Available() should return 0")
	}
	if cachePool.MaxCap() != 0 {
		t.Fatalf("cache pool MaxCap() should return 0")
	}
	if cachePool.WaitCount() != 0 {
		t.Fatalf("cache pool WaitCount() should return 0")
	}
	if cachePool.WaitTime() != 0 {
		t.Fatalf("cache pool WaitTime() should return 0")
	}
	if cachePool.IdleTimeout() != 0 {
		t.Fatalf("cache pool IdleTimeout() should return 0")
	}
	cachePool.Put(nil)
}
开发者ID:littleyang,项目名称:vitess,代码行数:33,代码来源:cache_pool_test.go

示例4: TestTableInfoWithoutRowCacheViaNoPKColumn

func TestTableInfoWithoutRowCacheViaNoPKColumn(t *testing.T) {
	fakecacheservice.Register()
	db := fakesqldb.Register()
	db.AddQuery("show index from `test_table`", &sqltypes.Result{})
	db.AddQuery("select * from `test_table` where 1 != 1", &sqltypes.Result{
		Fields: []*querypb.Field{{
			Name: "pk",
			Type: sqltypes.Int32,
		}},
	})
	db.AddQuery("describe `test_table`", &sqltypes.Result{
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			{
				sqltypes.MakeString([]byte("pk")),
				sqltypes.MakeString([]byte("int")),
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte("1")),
				sqltypes.MakeString([]byte{}),
			},
		},
	})

	cachePool := newTestTableInfoCachePool()
	cachePool.Open()
	defer cachePool.Close()
	tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
	if err != nil {
		t.Fatalf("failed to create a test table info")
	}
	if tableInfo.Cache != nil {
		t.Fatalf("table info's rowcache should be disabled")
	}
}
开发者ID:littleyang,项目名称:vitess,代码行数:35,代码来源:table_info_test.go

示例5: TestSchemaInfoCreateOrUpdateTableFailedDuetoExecErr

func TestSchemaInfoCreateOrUpdateTableFailedDuetoExecErr(t *testing.T) {
	fakecacheservice.Register()
	db := fakesqldb.Register()
	for query, result := range getSchemaInfoTestSupportedQueries() {
		db.AddQuery(query, result)
	}
	createOrDropTableQuery := fmt.Sprintf("%s and table_name = '%s'", baseShowTables, "test_table")
	db.AddQuery(createOrDropTableQuery, &mproto.QueryResult{
		// make this query fail
		RowsAffected: math.MaxUint64,
		Rows: [][]sqltypes.Value{
			createTestTableBaseShowTable("test_table"),
		},
	})
	schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
	appParams := sqldb.ConnParams{}
	dbaParams := sqldb.ConnParams{}
	cachePool := newTestSchemaInfoCachePool(false, schemaInfo.queryServiceStats)
	cachePool.Open()
	defer cachePool.Close()
	defer handleAndVerifyTabletError(
		t,
		"CreateOrUpdateTable should fail because it could not tables from MySQL",
		ErrFail,
	)
	schemaInfo.Open(&appParams, &dbaParams, getSchemaInfoTestSchemaOverride(), cachePool, false)
	defer schemaInfo.Close()
	schemaInfo.CreateOrUpdateTable(context.Background(), "test_table")
}
开发者ID:ruiaylin,项目名称:vitess,代码行数:29,代码来源:schema_info_test.go

示例6: TestTableInfoInvalidCardinalityInIndex

func TestTableInfoInvalidCardinalityInIndex(t *testing.T) {
	fakecacheservice.Register()
	db := fakesqldb.Register()
	for query, result := range getTestTableInfoQueries() {
		db.AddQuery(query, result)
	}
	db.AddQuery("show index from `test_table`", &sqltypes.Result{
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			{
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte("PRIMARY")),
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte("pk")),
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte("invalid")),
			},
		},
	})
	cachePool := newTestTableInfoCachePool()
	cachePool.Open()
	defer cachePool.Close()
	tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
	if err != nil {
		t.Fatalf("failed to create a table info: %v", err)
	}
	if len(tableInfo.PKColumns) != 1 {
		t.Fatalf("table should have one PK column although the cardinality is invalid")
	}
}
开发者ID:littleyang,项目名称:vitess,代码行数:31,代码来源:table_info_test.go

示例7: TestSchemaInfoOpenFailedDueToTableInfoErr

func TestSchemaInfoOpenFailedDueToTableInfoErr(t *testing.T) {
	fakecacheservice.Register()
	db := fakesqldb.Register()
	for query, result := range getSchemaInfoBaseTestQueries() {
		db.AddQuery(query, result)
	}
	db.AddQuery(baseShowTables, &mproto.QueryResult{
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			createTestTableBaseShowTable("test_table"),
		},
	})
	db.AddQuery("describe `test_table`", &mproto.QueryResult{
		// this will cause NewTableInfo error
		RowsAffected: math.MaxUint64,
	})
	schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
	appParams := sqldb.ConnParams{}
	dbaParams := sqldb.ConnParams{}
	cachePool := newTestSchemaInfoCachePool(false, schemaInfo.queryServiceStats)
	cachePool.Open()
	defer cachePool.Close()
	defer handleAndVerifyTabletError(
		t,
		"schema info Open should fail because NewTableInfo failed",
		ErrFail,
	)
	schemaInfo.Open(&appParams, &dbaParams, []SchemaOverride{}, cachePool, false)
}
开发者ID:ruiaylin,项目名称:vitess,代码行数:29,代码来源:schema_info_test.go

示例8: TestCachePoolStatsURL

func TestCachePoolStatsURL(t *testing.T) {
	cache := fakecacheservice.Register()
	fakesqldb.Register()
	rowCacheConfig := RowCacheConfig{
		Binary:      "ls",
		Connections: 100,
	}
	cachePool := newTestCachePool(rowCacheConfig, false)
	idleTimeout := 1 * time.Second
	cachePool.idleTimeout = idleTimeout
	cachePool.Open()
	request, _ := http.NewRequest("GET", fmt.Sprintf("%sstats", cachePool.statsURL), nil)
	response := httptest.NewRecorder()
	cachePool.ServeHTTP(response, request)
	// any memcache calls should fail
	cache.EnableCacheServiceError()
	response = httptest.NewRecorder()
	cachePool.ServeHTTP(response, request)
	cache.DisableCacheServiceError()
	cachePool.Close()
	response = httptest.NewRecorder()
	cachePool.ServeHTTP(response, request)
	body, _ := ioutil.ReadAll(response.Body)
	matcher := regexp.MustCompile("closed")
	if !matcher.Match(body) {
		t.Fatalf("stats page should contain 'closed', but got %s", string(body))
	}
}
开发者ID:littleyang,项目名称:vitess,代码行数:28,代码来源:cache_pool_test.go

示例9: TestSchemaInfoCreateOrUpdateTableFailedDuetoExecErr

func TestSchemaInfoCreateOrUpdateTableFailedDuetoExecErr(t *testing.T) {
	fakecacheservice.Register()
	db := fakesqldb.Register()
	for query, result := range getSchemaInfoTestSupportedQueries() {
		db.AddQuery(query, result)
	}
	createOrDropTableQuery := fmt.Sprintf("%s and table_name = '%s'", baseShowTables, "test_table")
	db.AddQuery(createOrDropTableQuery, &sqltypes.Result{
		// make this query fail
		RowsAffected: math.MaxUint64,
		Rows: [][]sqltypes.Value{
			createTestTableBaseShowTable("test_table"),
		},
	})
	schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, true)
	appParams := sqldb.ConnParams{Engine: db.Name}
	dbaParams := sqldb.ConnParams{Engine: db.Name}
	schemaInfo.cachePool.Open()
	defer schemaInfo.cachePool.Close()
	schemaInfo.Open(&appParams, &dbaParams, getSchemaInfoTestSchemaOverride(), false)
	defer schemaInfo.Close()
	originalSchemaErrorCount := schemaInfo.queryServiceStats.InternalErrors.Counts()["Schema"]
	// should silently fail: no errors returned, but increment a counter
	schemaInfo.CreateOrUpdateTable(context.Background(), "test_table")

	newSchemaErrorCount := schemaInfo.queryServiceStats.InternalErrors.Counts()["Schema"]
	schemaErrorDiff := newSchemaErrorCount - originalSchemaErrorCount
	if schemaErrorDiff != 1 {
		t.Errorf("InternalErrors.Schema counter should have increased by 1, instead got %v", schemaErrorDiff)
	}
}
开发者ID:Rastusik,项目名称:vitess,代码行数:31,代码来源:schema_info_test.go

示例10: TestSchemaInfoGetPlanPanicDuetoEmptyQuery

func TestSchemaInfoGetPlanPanicDuetoEmptyQuery(t *testing.T) {
	fakecacheservice.Register()
	db := fakesqldb.Register()
	for query, result := range getSchemaInfoTestSupportedQueries() {
		db.AddQuery(query, result)
	}
	schemaInfo := newTestSchemaInfo(10, 10*time.Second, 10*time.Second, false)
	appParams := sqldb.ConnParams{}
	dbaParams := sqldb.ConnParams{}
	cachePool := newTestSchemaInfoCachePool(false, schemaInfo.queryServiceStats)
	cachePool.Open()
	defer cachePool.Close()
	schemaOverrides := getSchemaInfoTestSchemaOverride()
	// test cache type RW
	schemaInfo.Open(&appParams, &dbaParams, schemaOverrides, cachePool, true)
	defer schemaInfo.Close()

	ctx := context.Background()
	logStats := newLogStats("GetPlanStats", ctx)
	defer handleAndVerifyTabletError(
		t,
		"schema info GetPlan should fail because of empty query",
		ErrFail,
	)
	schemaInfo.GetPlan(ctx, logStats, "")
}
开发者ID:ruiaylin,项目名称:vitess,代码行数:26,代码来源:schema_info_test.go

示例11: TestSchemaInfoOpenWithSchemaOverride

func TestSchemaInfoOpenWithSchemaOverride(t *testing.T) {
	fakecacheservice.Register()
	db := fakesqldb.Register()
	for query, result := range getSchemaInfoTestSupportedQueries() {
		db.AddQuery(query, result)
	}
	schemaInfo := newTestSchemaInfo(10, 10*time.Second, 10*time.Second, false)
	appParams := sqldb.ConnParams{}
	dbaParams := sqldb.ConnParams{}
	cachePool := newTestSchemaInfoCachePool(false, schemaInfo.queryServiceStats)
	cachePool.Open()
	defer cachePool.Close()
	schemaOverrides := getSchemaInfoTestSchemaOverride()
	// test cache type RW
	schemaInfo.Open(&appParams, &dbaParams, schemaOverrides, cachePool, true)
	testTableInfo := schemaInfo.GetTable("test_table_01")
	if testTableInfo.Table.CacheType != schema.CACHE_RW {
		t.Fatalf("test_table_01's cache type should be RW")
	}
	schemaInfo.Close()
	// test cache type W
	schemaInfo.Open(&appParams, &dbaParams, schemaOverrides, cachePool, true)
	testTableInfo = schemaInfo.GetTable("test_table_02")
	if testTableInfo.Table.CacheType != schema.CACHE_W {
		t.Fatalf("test_table_02's cache type should be W")
	}
	schemaInfo.Close()
}
开发者ID:ruiaylin,项目名称:vitess,代码行数:28,代码来源:schema_info_test.go

示例12: TestTableInfoFailBecauseUnableToRetrieveTableIndex

func TestTableInfoFailBecauseUnableToRetrieveTableIndex(t *testing.T) {
	fakecacheservice.Register()
	db := fakesqldb.Register()
	for query, result := range getTestTableInfoQueries() {
		db.AddQuery(query, result)
	}
	db.AddRejectedQuery("show index from `test_table`", errRejected)
	cachePool := newTestTableInfoCachePool()
	cachePool.Open()
	defer cachePool.Close()
	_, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
	if err == nil {
		t.Fatalf("table info creation should fail because it is unable to get test_table index")
	}
}
开发者ID:littleyang,项目名称:vitess,代码行数:15,代码来源:table_info_test.go

示例13: TestTableInfoWithoutRowCacheViaUnknownPKColumnType

func TestTableInfoWithoutRowCacheViaUnknownPKColumnType(t *testing.T) {
	fakecacheservice.Register()
	db := fakesqldb.Register()
	db.AddQuery("show index from `test_table`", &mproto.QueryResult{
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			[]sqltypes.Value{
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte("PRIMARY")),
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte("pk")),
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte("300")),
			},
		},
	})
	db.AddQuery("select * from `test_table` where 1 != 1", &mproto.QueryResult{
		Fields: []mproto.Field{{
			Name: "pk",
			Type: mysql.TypeNewDecimal,
		}},
	})
	db.AddQuery("describe `test_table`", &mproto.QueryResult{
		RowsAffected: 1,
		Rows: [][]sqltypes.Value{
			[]sqltypes.Value{
				sqltypes.MakeString([]byte("pk")),
				sqltypes.MakeString([]byte("decimal")),
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte{}),
				sqltypes.MakeString([]byte("1")),
				sqltypes.MakeString([]byte{}),
			},
		},
	})

	cachePool := newTestTableInfoCachePool()
	cachePool.Open()
	defer cachePool.Close()
	tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
	if err != nil {
		t.Fatalf("failed to create a test table info")
	}
	if tableInfo.Cache != nil {
		t.Fatalf("table info's rowcache should be disabled")
	}
}
开发者ID:hadmagic,项目名称:vitess,代码行数:48,代码来源:table_info_test.go

示例14: TestCachePoolOpenWithInvalidBinary

func TestCachePoolOpenWithInvalidBinary(t *testing.T) {
	fakecacheservice.Register()
	fakesqldb.Register()
	rowCacheConfig := RowCacheConfig{
		Binary:      "invalid_binary",
		Connections: 100,
	}
	cachePool := newTestCachePool(rowCacheConfig, false)
	defer func() {
		if e := recover(); e == nil {
			t.Fatalf("open a cache pool with an invalid rowCacheConfig.Binary should panic")
		}
	}()
	cachePool.Open()
	cachePool.Close()
}
开发者ID:littleyang,项目名称:vitess,代码行数:16,代码来源:cache_pool_test.go

示例15: TestCachePoolFailToStartBecauseCacheServiceWasDown

func TestCachePoolFailToStartBecauseCacheServiceWasDown(t *testing.T) {
	cache := fakecacheservice.Register()
	fakesqldb.Register()
	testUtils := &testUtils{}
	rowCacheConfig := RowCacheConfig{
		Binary:      "ls",
		Connections: 100,
	}
	cachePool := newTestCachePool(rowCacheConfig, false)
	idleTimeout := 1 * time.Second
	cachePool.idleTimeout = idleTimeout
	// any memcache calls should fail
	cache.EnableCacheServiceError()
	defer testUtils.checkTabletErrorWithRecover(t, ErrFatal, "can't communicate with cache service")
	cachePool.Open()
}
开发者ID:littleyang,项目名称:vitess,代码行数:16,代码来源:cache_pool_test.go


注:本文中的github.com/youtube/vitess/go/vt/tabletserver/fakecacheservice.Register函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。