コード例 #1
0
ファイル: dynamodb_test.go プロジェクト: Comcast/rulio
func TestDynamoThroughput(t *testing.T) {
	location := "there"
	n := 100

	ctx := core.NewContext(location)
	store, err := NewStorage(ctx, testConfig)
	if noConnection(err) {
		t.Skip()
	}
	if err != nil {
		t.Fatal(err)
	}

	state, err := core.NewLinearState(ctx, location, store)
	if err != nil {
		t.Fatal(err)
	}

	loc, err := core.NewLocation(ctx, location, state, nil)
	if err != nil {
		t.Fatal(err)
	}

	loc.Clear(ctx)

	then := time.Now().UTC().UnixNano()
	for i := 0; i < n; i++ {
		fact := fmt.Sprintf(`{"likes":"beer %d"}`, i)
		_, err := loc.AddFact(ctx, "", core.MustMap(fact))
		if err != nil {
			// ProvisionedThroughputExceededException: The
			// level of configured provisioned throughput
			// for the table was exceeded. Consider
			// increasing your provisioning level with the
			// UpdateTable API
			log.Printf("Died at iteration %d", i)
			log.Fatal(err)
		}
	}
	elapsed := time.Now().UTC().UnixNano() - then
	log.Printf("elapsed %d us", elapsed/1000)

	then = time.Now().UTC().UnixNano()
	sr, err := loc.SearchFacts(ctx, core.MustMap(`{"likes":"?x"}`), false)
	if err != nil {
		log.Fatal(err)
	}
	elapsed = time.Now().UTC().UnixNano() - then
	log.Printf("elapsed %d us", elapsed/1000)
	log.Printf("# SearchFacts found %d\n", len(sr.Found))
}
コード例 #2
0
ファイル: dynamodb_test.go プロジェクト: Comcast/rulio
func TestDynamoFacts(t *testing.T) {
	location := "there"

	ctx := core.NewContext("test")

	store, err := NewStorage(ctx, testConfig)
	if noConnection(err) {
		t.Skip()
	}
	if err != nil {
		t.Fatal(err)
	}

	state, err := core.NewLinearState(ctx, location, store)
	if err != nil {
		t.Fatal(err)
	}

	loc, err := core.NewLocation(ctx, location, state, nil)
	if err != nil {
		t.Fatal(err)
	}

	sr, err := loc.SearchFacts(ctx, core.MustMap(`{"likes":"?x"}`), false)
	if err != nil {
		t.Fatal(err)
	}
	log.Printf("# SearchFacts %v %v\n", *sr, err)

	loc.Clear(ctx)

	id, err := loc.AddFact(ctx, "", core.MustMap(`{"likes":"chips"}`))
	log.Printf("# AddFact %s %v\n", id, err)
	id, err = loc.AddFact(ctx, "", core.MustMap(`{"likes":"beer"}`))
	log.Printf("# AddFact %s %v\n", id, err)
	id, err = loc.AddFact(ctx, "", core.MustMap(`{"wants":"tacos"}`))
	log.Printf("# AddFact %s %v\n", id, err)
	id, err = loc.AddFact(ctx, "", core.MustMap(`{"wants":"tacos"}`))
	log.Printf("# AddFact %s %v\n", id, err)

	sr, err = loc.SearchFacts(ctx, core.MustMap(`{"wants":"?x"}`), false)
	log.Printf("# SearchFacts 1 %v %v\n", *sr, err)

	id, err = loc.RemFact(ctx, id)
	log.Printf("# RemFact %v %v\n", id, err)

	sr, err = loc.SearchFacts(ctx, core.MustMap(`{"wants":"?x"}`), false)
	log.Printf("# SearchFacts 2 %v %v\n", *sr, err)
}