示例#1
0
func TestMarshalRoundTrip(t *testing.T) {
	const p, pPrime = 14, 25

	testCases := []struct {
		p, pPrime uint
	}{
		{5, 10},
		{10, 25},
		{15, 25},
	}

	for _, testCase := range testCases {
		h := NewHll(testCase.p, testCase.pPrime)
		for i := uint64(0); i <= 1e5; i++ {
			if i%5000 == 0 {
				// Every N elements, do a round-trip marshal and unmarshal and make sure cardinality is
				// preserved.
				jBuf, err := json.Marshal(h)
				assert.Equalf(t, nil, err, "%v", err)

				rt := &Hll{}
				err = json.Unmarshal(jBuf, rt)
				assert.Equalf(t, nil, err, "%v", err)

				assert.Equal(t, rt.Cardinality(), h.Cardinality())
			}

			h.Add(randUint64(t))
		}

		assert.T(t, !h.isSparse) // Ensure we stored enough to use the dense representation.
	}
}
示例#2
0
func TestCsvModuleArguments(t *testing.T) {
	skipIfCgoCheckActive(t)

	db := open(t)
	defer checkClose(db, t)
	err := LoadCsvModule(db)
	checkNoError(t, err, "couldn't create CSV module: %s")
	for _, tt := range csvModuleTests {
		ddl := []byte("CREATE VIRTUAL TABLE vtab USING csv(")
		for i, arg := range tt.Args {
			if i > 0 {
				ddl = append(ddl, ", "...)
			}
			ddl = append(ddl, arg...)
		}
		ddl = append(ddl, ")"...)
		//println("DDL: ", string(ddl))
		err = db.Exec(string(ddl))
		if tt.Error != "" {
			if err == nil || !strings.Contains(err.Error(), tt.Error) {
				t.Errorf("%s: error %v, want error %q", tt.Name, err, tt.Error)
			}
			continue
		} else {
			checkNoError(t, err, "couldn't create CSV virtual table: %s")
		}

		if tt.Count > 0 {
			var count int
			err = db.OneValue("SELECT count(1) FROM vtab", &count)
			checkNoError(t, err, "couldn't select from CSV virtual table: %s")
			assert.Equalf(t, tt.Count, count, "%s: got %d rows, want %d", tt.Name, count, tt.Count)
		}

		/*var schema string
		err = db.OneValue("SELECT sql FROM sqlite_master WHERE name like ? and type = ?", &schema, "vtab", "table")
		checkNoError(t, err, "couldn't get schema of CSV virtual table: %s")
		println("SCHEMA:", schema)*/

		if len(tt.Names) > 0 {
			cols, err := db.Columns("", "vtab")
			checkNoError(t, err, "couldn't get columns of CSV virtual table: %s")
			assert.Equalf(t, len(tt.Names), len(cols), "%s: got %d columns, want %d", tt.Name, len(cols), len(tt.Names))
			for i, col := range cols {
				assert.Equalf(t, tt.Names[i], col.Name, "%s: got %s, want %s as column name at %d", tt.Name, col.Name, tt.Names[i], i+1)
			}
		}
		if len(tt.Types) > 0 {
			cols, err := db.Columns("", "vtab")
			checkNoError(t, err, "couldn't get columns of CSV virtual table: %s")
			assert.Equalf(t, len(tt.Types), len(cols), "%s: got %d columns, want %d", tt.Name, len(cols), len(tt.Types))
			for i, col := range cols {
				assert.Equalf(t, tt.Types[i], col.DataType, "%s: got %s, want %s as column type at %d", tt.Name, col.DataType, tt.Types[i], i+1)
			}
		}

		err = db.Exec("DROP TABLE vtab")
		checkNoError(t, err, "couldn't drop CSV virtual table: %s")
	}
}
示例#3
0
文件: mc_test.go 项目: memcachier/mc
// Test the quit command works...
func TestQuit(t *testing.T) {
	testInit(t)

	const (
		Key1 = "fooz"
		Val1 = "barz"
	)

	_, err := cn.Set(Key1, Val1, 0, 0, 0)
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)

	v, _, _, err := cn.Get(Key1)
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)
	assert.Equalf(t, Val1, v, "wrong value: %s", v)

	err = cn.Quit()
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)

	_, _, _, err = cn.Get(Key1)
	assert.NotEqual(t, mcNil, err, "expected an error (closed connection)")

	err = cn.Quit()
	assert.NotEqual(t, mcNil, err, "expected an error (closed connection)")

	cn = nil
}
示例#4
0
func DoTestPatchFileAppend(t *testing.T, mkrepo repoMaker) {
	tg := treegen.New()
	treeSpec := tg.D("foo", tg.F("bar", tg.B(42, 65537), tg.B(43, 65537)))

	srcpath := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(srcpath)
	srcRepo := mkrepo(t)
	defer srcRepo.Close()
	srcStore, err := fs.NewLocalStore(srcpath, srcRepo)
	assert.T(t, err == nil)

	tg = treegen.New()
	treeSpec = tg.D("foo", tg.F("bar", tg.B(42, 65537)))

	dstpath := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(dstpath)
	dstRepo := mkrepo(t)
	defer dstRepo.Close()
	dstStore, err := fs.NewLocalStore(dstpath, dstRepo)
	assert.T(t, err == nil)

	patchPlan := NewPatchPlan(srcStore, dstStore)
	//	printPlan(patchPlan)

	complete := false
	for i, cmd := range patchPlan.Cmds {
		switch {
		case i == 0:
			localTemp, isTemp := cmd.(*LocalTemp)
			assert.T(t, isTemp)
			assert.Equal(t, filepath.Join(dstpath, "foo", "bar"), localTemp.Path.Resolve())
		case i >= 1 && i <= 8:
			ltc, isLtc := cmd.(*LocalTempCopy)
			assert.Tf(t, isLtc, "cmd %d", i)
			assert.Equal(t, ltc.LocalOffset, ltc.TempOffset)
			assert.Equal(t, int64(fs.BLOCKSIZE), ltc.Length)
			assert.Equal(t, int64(0), ltc.LocalOffset%int64(fs.BLOCKSIZE))
		case i == 9:
			stc, isStc := cmd.(*SrcTempCopy)
			assert.T(t, isStc)
			assert.Equal(t, int64(65538), stc.Length)
		case i == 10:
			_, isRwt := cmd.(*ReplaceWithTemp)
			assert.T(t, isRwt)
			complete = true
		case i > 10:
			t.Fatalf("too many commands")
		}
	}
	assert.T(t, complete, "missing expected number of commands")

	failedCmd, err := patchPlan.Exec()
	assert.Tf(t, failedCmd == nil && err == nil, "%v: %v", failedCmd, err)

	srcRoot, errors := fs.IndexDir(srcpath, fs.NewMemRepo())
	assert.Equalf(t, 0, len(errors), "%v", errors)
	dstRoot, errors := fs.IndexDir(dstpath, fs.NewMemRepo())
	assert.Equalf(t, 0, len(errors), "%v", errors)
	assert.Equal(t, srcRoot.Info().Strong, dstRoot.Info().Strong)
}
示例#5
0
// 18.5.12. Get typed relationships
func TestGetTypedRelationships(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	relType0 := rndStr(t)
	relType1 := rndStr(t)
	n0, _ := db.CreateNode(Props{})
	n1, _ := db.CreateNode(Props{})
	r0, _ := n0.Relate(relType0, n1.Id(), Props{})
	r1, _ := n0.Relate(relType1, n1.Id(), Props{})
	// Check one type of relationship
	rels, err := n0.Relationships(relType0)
	if err != nil {
		t.Error(err)
	}
	assert.Equalf(t, len(rels), 1, "Wrong number of relationships")
	_, present := rels.Map()[r0.Id()]
	assert.Tf(t, present, "Missing expected relationship")
	// Check two types of relationship together
	rels, err = n0.Relationships(relType0, relType1)
	if err != nil {
		t.Error(err)
	}
	assert.Equalf(t, len(rels), 2, "Wrong number of relationships")
	for _, r := range []*Relationship{r0, r1} {
		_, present := rels.Map()[r.Id()]
		assert.Tf(t, present, "Missing expected relationship")
	}
}
示例#6
0
func set(t *testing.T, key, val string, ocas uint64, flags, exp uint32, ecas uint64, eerr error) {
	ocas, err := cn.Set(key, val, 0, 0, 0)
	assert.Equalf(t, eerr, err, "shouldn't be an error: %v", err)
	if ecas != 0 {
		assert.Equalf(t, ecas, ocas, "wrong CAS for get: %d != %d", ocas, ecas)
	}
}
示例#7
0
func DoTestVisitDirsOnly(t *testing.T, repo fs.NodeRepo) {
	dir, errors := fs.IndexDir("../../testroot/", repo)
	assert.T(t, dir != nil)
	assert.Equalf(t, 0, len(errors), "%v", errors)

	collect := []fs.Dir{}
	visited := []fs.Node{}

	fs.Walk(dir, func(node fs.Node) bool {
		visited = append(visited, node)

		d, ok := node.(fs.Dir)
		if ok {
			collect = append(collect, d)
			return true
		}

		_, ok = node.(fs.File)
		if ok {
			return false
		}

		t.Errorf("Unexpected type during visit: %v", node)
		return true
	})

	assert.Equalf(t, 3, len(collect), "Unexpected dirs in testroot/: %v", collect)

	for _, node := range visited {
		_, ok := node.(fs.Block)
		if ok {
			t.Fatalf("Should not have gotten a block, we told visitor to stop at file level.")
		}
	}
}
示例#8
0
// Test that the matcher matches all blocks in two identical files.
func TestMatchIdentity(t *testing.T) {
	srcPath := "../../testroot/My Music/0 10k 30.mp4"
	dstPath := srcPath

	match, err := Match(srcPath, dstPath)
	assert.Tf(t, err == nil, "%v", err)

	nMatches := 0
	for i, match := range match.BlockMatches {
		assert.Equalf(t, int64(0), match.DstOffset%int64(fs.BLOCKSIZE),
			"Destination match block# %d not aligned with blocksize! (offset=%d)",
			i, match.DstOffset)
		nMatches++
	}

	fileInfo, err := os.Stat(srcPath)
	if fileInfo == nil {
		t.Fatalf("Cannot stat file %s: ", err.String())
	} else {
		nExpectMatches := fileInfo.Size / int64(fs.BLOCKSIZE)
		if fileInfo.Size%int64(fs.BLOCKSIZE) > 0 {
			nExpectMatches++
		}

		assert.Equal(t, nExpectMatches, int64(nMatches))
	}

	lastBlockSize := fileInfo.Size - int64(match.BlockMatches[14].DstOffset)
	assert.Equalf(t, int64(5419), lastBlockSize,
		"Unxpected last block size: %d", lastBlockSize)
}
示例#9
0
// Make sure that after roundtripping, an Hll is still usable and behaves identically.
func TestUsageAfterMarshalRoundTrip(t *testing.T) {
	h := NewHll(10, 20)

	h.Add(randUint64(t))
	h.Add(randUint64(t))
	h.Add(randUint64(t))

	jBuf, err := json.Marshal(h)
	assert.Equalf(t, nil, err, "%v", err)

	rt := &Hll{}
	err = json.Unmarshal(jBuf, rt)
	assert.Equalf(t, nil, err, "%v", err)

	for i := uint64(100); i < 1000; i++ {
		r := randUint64(t)
		rt.Add(r)
		h.Add(r)

		assert.Equalf(t, rt.isSparse, h.isSparse, "%v", i)
		// fmt.Printf("2 calling rt.Cardinality(), rt.isSparse=%v\n", rt.isSparse)
		rtCard := rt.Cardinality()
		// fmt.Printf("3\n")
		hCard := h.Cardinality()
		assert.Equal(t, rtCard, hCard, i)
	}

	assert.T(t, !h.isSparse)
}
示例#10
0
func TestConnGrant(t *testing.T) {
	for _, tst := range grantTests {
		ok := tst.c.grant(tst.sk)
		assert.Equalf(t, tst.ok, ok, "%# v", pretty.Formatter(tst))
		assert.Equalf(t, tst.r, tst.c.raccess, "%# v", pretty.Formatter(tst))
		assert.Equalf(t, tst.w, tst.c.waccess, "%# v", pretty.Formatter(tst))
	}
}
示例#11
0
func verifyLexerTokens(t *testing.T, l *Lexer, tokens []Token) {
	for _, goodToken := range tokens {
		tok := l.NextToken()
		//u.Debugf("%#v  %#v", tok, goodToken)
		assert.Equalf(t, tok.T, goodToken.T, "want='%v' has %v ", goodToken.T, tok.T)
		assert.Equalf(t, tok.V, goodToken.V, "want='%v' has %v ", goodToken.V, tok.V)
	}
}
示例#12
0
文件: mc_test.go 项目: memcachier/mc
// Test the version command works...
func TestVersion(t *testing.T) {
	testInit(t)

	ver, err := cn.Version()
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)
	good, errRegex := regexp.MatchString("[0-9]+\\.[0-9]+\\.[0-9]+", ver)
	assert.Equalf(t, nil, errRegex, "unexpected error: %v", errRegex)
	assert.Equalf(t, good, true, "version of unexcpected form: %s", ver)
}
示例#13
0
func verifyJsonTokens(t *testing.T, expString string, tokens []Token) {
	l := NewJsonLexer(expString)
	for i, goodToken := range tokens {
		tok := l.NextToken()
		//u.Debugf("%#v  %#v", tok, goodToken)
		assert.Equalf(t, tok.T, goodToken.T, "%d want token type ='%v' has %v ", i, goodToken.T, tok.T)
		assert.Equalf(t, tok.V, goodToken.V, "%d want token value='%v' has %v ", i, goodToken.V, tok.V)
	}
}
示例#14
0
func verifyTokens(t *testing.T, sql string, tokens []lex.Token) {
	l := lex.NewLexer(sql, InfluxQlDialect)
	for _, goodToken := range tokens {
		tok := l.NextToken()
		u.Debugf("%#v  %#v", tok, goodToken)
		assert.Equalf(t, tok.V, goodToken.V, "has='%v' want='%v'", tok.V, goodToken.V)
		assert.Equalf(t, tok.T, goodToken.T, "has='%v' want='%v'", tok.V, goodToken.V)
	}
}
示例#15
0
func verifyExpr2Tokens(t *testing.T, expString string, tokens []Token) {
	l := NewLexer(expString, LogicalExpressionDialect)
	for _, goodToken := range tokens {
		tok := l.NextToken()
		//u.Debugf("%#v  %#v", tok, goodToken)
		assert.Equalf(t, tok.T, goodToken.T, "want='%v' has %v ", goodToken.T, tok.T)
		assert.Equalf(t, tok.V, goodToken.V, "want='%v' has %v ", goodToken.V, tok.V)
	}
}
示例#16
0
func verifyTokens(t *testing.T, sql string, tokens []Token) {
	l := NewSqlLexer(sql)
	u.Debugf("sql: %v", sql)
	for _, goodToken := range tokens {
		tok := l.NextToken()
		//u.Debugf("%#v  %#v", tok, goodToken)
		assert.Equalf(t, tok.T, goodToken.T, "want='%v' has %v ", goodToken.T, tok.T)
		assert.Equalf(t, tok.V, goodToken.V, "want='%v' has %v ", goodToken.V, tok.V)
	}
}
func verifyFilterQLTokens(t *testing.T, ql string, tokens []Token) {
	l := NewFilterQLLexer(ql)
	u.Debugf("filterql: %v", ql)
	for _, goodToken := range tokens {
		tok := l.NextToken()
		//u.Debugf("%#v  %#v", tok, goodToken)
		assert.Equalf(t, tok.T, goodToken.T, "want='%v' has %v %v", goodToken.T, tok.T, l.PeekX(10))
		assert.Equalf(t, tok.V, goodToken.V, "want='%v' has %v ", goodToken.V, tok.V)
	}
}
示例#18
0
func get(t *testing.T, key, val string, ecas uint64, eerr error) {
	v, ocas, _, err := cn.Get(key)
	assert.Equalf(t, eerr, err, "shouldn't be an error: %v", err)
	if eerr == nil && val != "" {
		assert.Equalf(t, val, v, "wrong value: %v", v)
	}
	if ecas != 0 {
		assert.Equalf(t, ecas, ocas, "wrong CAS for get: %d != %d", ocas, ecas)
	}
}
示例#19
0
文件: conn_test.go 项目: zeebo/pq.go
func TestConnPrepareErr(t *testing.T) {
	nc, err := net.Dial("tcp", "localhost:5432")
	assert.Equalf(t, nil, err, "%v", err)

	cn, err := New(nc, map[string]string{"user": os.Getenv("USER")}, "")
	assert.Equalf(t, nil, err, "%v", err)

	_, err = cn.Prepare("SELECT length($1) AS ZOMG! AN ERR")
	assert.NotEqual(t, nil, err)
}
示例#20
0
func DoTestPatchRenameScope(t *testing.T, mkrepo repoMaker) {
	tg := treegen.New()
	treeSpec := tg.D("foo",
		tg.F("bar", tg.B(6806, 65536)),
		tg.F("baz", tg.B(6806, 65536)))

	srcpath := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(srcpath)
	srcRepo := mkrepo(t)
	defer srcRepo.Close()
	srcStore, err := fs.NewLocalStore(srcpath, srcRepo)
	assert.T(t, err == nil)

	tg = treegen.New()
	treeSpec = tg.D("foo",
		tg.F("baz", tg.B(6806, 65536)),
		tg.F("blop", tg.B(6806, 65536)))

	dstpath := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(dstpath)
	dstRepo := mkrepo(t)
	defer dstRepo.Close()
	dstStore, err := fs.NewLocalStore(dstpath, dstRepo)
	assert.T(t, err == nil)

	patchPlan := NewPatchPlan(srcStore, dstStore)
	//	printPlan(patchPlan)

	failedCmd, err := patchPlan.Exec()
	assert.Tf(t, failedCmd == nil && err == nil, "%v: %v", failedCmd, err)

	// The actual content of dst after the patch depends on
	// which file the repo chooses when matching foo/bar
	// to baz or blop in dst.
	//
	// If blop matches, it will get renamed to bar and the trees will
	// become identical. However if baz matches, blop will be left in place.

	srcDir, errors := fs.IndexDir(srcpath, fs.NewMemRepo())
	assert.Equalf(t, 0, len(errors), "%v", errors)
	dstDir, errors := fs.IndexDir(dstpath, fs.NewMemRepo())
	assert.Equalf(t, 0, len(errors), "%v", errors)

	for _, path := range []string{"foo/bar", "foo/baz"} {
		srcNode, has := fs.Lookup(srcDir, path)
		assert.T(t, has)
		dstNode, has := fs.Lookup(dstDir, path)
		assert.T(t, has)

		assert.Equal(t,
			srcNode.(fs.File).Info().Strong,
			dstNode.(fs.File).Info().Strong)
	}
}
示例#21
0
// start connection
func testInit(t *testing.T) *Conn {
	if cn == nil {
		nc, err := net.Dial("tcp", mcAddr)
		assert.Equalf(t, nil, err, "%v", err)
		cn = &Conn{rwc: nc, buf: new(bytes.Buffer)}
		testAuth(cn, t)
		cn.Flush(0)
		assert.Equalf(t, nil, err, "unexpected error: %v", err)
	}
	return cn
}
示例#22
0
文件: conn_test.go 项目: zeebo/pq.go
func TestAuthCleartextPassword(t *testing.T) {
	c, err := OpenRaw("postgres://*****:*****@localhost:5432/" + os.Getenv("USER"))
	//c, err := OpenRaw("postgres://gopqtest@localhost:5432/"+os.Getenv("USER"))
	assert.Equalf(t, nil, err, "%v", err)

	s, err := c.Prepare("SELECT 1")
	assert.Equalf(t, nil, err, "%v", err)

	_, err = s.Exec(nil)
	assert.Equalf(t, nil, err, "%v", err)
}
示例#23
0
func TestLimit(t *testing.T) {
	db := open(t)
	defer checkClose(db, t)

	limitVariableNumber := db.Limit(LimitVariableNumber)
	assert.Tf(t, limitVariableNumber < 1e6, "unexpected value for LimitVariableNumber: %d", limitVariableNumber)
	oldLimitVariableNumber := db.SetLimit(LimitVariableNumber, 99)
	assert.Equalf(t, limitVariableNumber, oldLimitVariableNumber, "got LimitVariableNumber: %d; want %d", oldLimitVariableNumber, limitVariableNumber)
	limitVariableNumber = db.Limit(LimitVariableNumber)
	assert.Equalf(t, int32(99), limitVariableNumber, "got LimitVariableNumber: %d; want %d", limitVariableNumber, 99)

}
示例#24
0
func TestClassifierJSON(t *testing.T) {
	classifier := NewClassifier()
	classifier.trainWithTestData()

	b, err := classifier.MarshalJSON()
	assert.Equalf(t, nil, err, "Error marshaling JSON: %v\n", err)

	newclass, err := NewClassifierFromJSON(b)
	assert.Equalf(t, nil, err, "Error unmarshaling JSON: %v\n", err)

	assert.Equalf(t, 5, len(newclass.Matrix.Tokens), "Incorrect token length")
	assert.Equalf(t, 2, len(newclass.Matrix.Classes), "Incorrect class length")
}
示例#25
0
文件: conn_test.go 项目: zeebo/pq.go
func TestConnNotify(t *testing.T) {
	nc, err := net.Dial("tcp", "localhost:5432")
	assert.Equalf(t, nil, err, "%v", err)

	cn, err := New(nc, map[string]string{"user": os.Getenv("USER")}, "")
	assert.Equalf(t, nil, err, "%v", err)

	// Listen
	lstmt, err := cn.Prepare("LISTEN test")
	assert.Equalf(t, nil, err, "%v", err)

	_, err = lstmt.Exec(nil)
	assert.Equalf(t, nil, err, "%v", err)

	err = lstmt.Close()
	assert.Equalf(t, nil, err, "%v", err)

	// Notify
	nstmt, err := cn.Prepare("NOTIFY test, 'foo'")
	assert.Equalf(t, nil, err, "%v", err)

	_, err = nstmt.Exec(nil)
	assert.Equalf(t, nil, err, "%v", err)

	err = nstmt.Close()
	assert.Equalf(t, nil, err, "%v", err)

	n := <-cn.Notifies
	assert.NotEqual(t, 0, n.Pid)
	assert.Equal(t, "test", n.From)
	assert.Equal(t, "foo", n.Payload)
}
示例#26
0
文件: conn_test.go 项目: zeebo/pq.go
func TestConnPrepare(t *testing.T) {
	nc, err := net.Dial("tcp", "localhost:5432")
	assert.Equalf(t, nil, err, "%v", err)

	cn, err := New(nc, map[string]string{"user": os.Getenv("USER")}, "")
	assert.Equalf(t, nil, err, "%v", err)

	stmt, err := cn.Prepare("SELECT length($1) AS foo WHERE true = $2")
	assert.Equalf(t, nil, err, "%v", err)
	assert.Equal(t, 2, stmt.NumInput())

	rows, err := stmt.Query([]driver.Value{"testing", true})
	assert.Equalf(t, nil, err, "%v", err)
	assert.Equal(t, []string{"foo"}, rows.Columns())

	dest := make([]driver.Value, 1)
	err = rows.Next(dest)
	assert.Equalf(t, nil, err, "%v", err)
	assert.Equal(t, []driver.Value{"7"}, dest)

	err = rows.Next(dest)
	assert.Equalf(t, io.EOF, err, "%v", err)

	rows, err = stmt.Query([]driver.Value{"testing", false})
	assert.Equalf(t, nil, err, "%v", err)
	assert.Equal(t, []string{"foo"}, rows.Columns())

	err = rows.Next(dest)
	assert.Equalf(t, io.EOF, err, "%v", err)
}
示例#27
0
文件: mc_test.go 项目: memcachier/mc
// Some basic tests that functions work
func TestMCSimple(t *testing.T) {
	testInit(t)

	const (
		Key1 = "foo"
		Val1 = "bar"
		Val2 = "bar-bad"
		Val3 = "bar-good"
	)

	_, _, _, err := cn.Get(Key1)
	assert.Equalf(t, ErrNotFound, err, "expected missing key: %v", err)

	// unconditional SET
	_, err = cn.Set(Key1, Val1, 0, 0, 0)
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)
	cas, err := cn.Set(Key1, Val1, 0, 0, 0)
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)

	// make sure CAS works
	_, err = cn.Set(Key1, Val2, 0, 0, cas+1)
	assert.Equalf(t, ErrKeyExists, err, "expected CAS mismatch: %v", err)

	// check SET actually set the correct value...
	v, _, cas2, err := cn.Get(Key1)
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)
	assert.Equalf(t, Val1, v, "wrong value: %s", v)
	assert.Equalf(t, cas, cas2, "CAS shouldn't have changed: %d, %d", cas, cas2)

	// use correct CAS...
	cas2, err = cn.Set(Key1, Val3, 0, 0, cas)
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)
	assert.NotEqual(t, cas, cas2)
}
示例#28
0
文件: mc_test.go 项目: memcachier/mc
// Testing Max SIZE of values...
// Testing if when you set a key/value with a bad value (e.g > 1MB) does that
// remove the existing key/value still or leave it intact?
func TestSetBadRemovePrevious(t *testing.T) {
	testInit(t)

	const (
		// Larger than this memcached doesn't like for key 'foo' (with defaults)
		MaxValSize = 1024*1024 - 80
		Key        = "foo"
		Val        = "bar"
	)

	// check basic get/set works first
	_, err := cn.Set(Key, Val, 0, 0, 0)
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)
	v, _, _, err := cn.Get(Key)
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)
	assert.Equalf(t, Val, v, "wrong value: %s", v)

	// Max GOOD ValUE

	// generate random bytes
	data := make([]byte, MaxValSize)
	for i := 0; i < MaxValSize; i++ {
		data[i] = byte(rand.Int())
	}

	val := string(data)
	_, err = cn.Set(Key, val, 0, 0, 0)
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)
	v, _, _, err = cn.Get(Key)
	assert.Equalf(t, mcNil, err, "unexpected error: %v", err)
	assert.Equalf(t, val, v, "wrong value: (too big to print)")

	// Max GOOD ValUE * 2

	// generate random bytes
	data = make([]byte, 2*MaxValSize)
	for i := 0; i < 2*MaxValSize; i++ {
		data[i] = byte(rand.Int())
	}

	val2 := string(data)
	_, err = cn.Set(Key, val2, 0, 0, 0)
	assert.Equalf(t, ErrValueTooLarge, err, "expected too large error: %v", err)
	v, _, _, err = cn.Get(Key)
	if err == mcNil {
		fmt.Println("\tmemcached removes the old value... so expecting no key")
		fmt.Println("\tnot an error but just a different semantics than memcached")
		// well it should at least be the old value stil..
		assert.Equalf(t, val, v, "wrong value: (too big to print)")
	} else {
		assert.Equalf(t, ErrNotFound, err, "expected no key: %v", err)
	}
}
示例#29
0
func DoTestVisitBlocks(t *testing.T, repo fs.NodeRepo) {
	dir, errors := fs.IndexDir("../../testroot/", repo)
	assert.T(t, dir != nil)
	assert.Equalf(t, 0, len(errors), "%v", errors)

	collect := []fs.Block{}

	fs.Walk(dir, func(node fs.Node) bool {
		b, ok := node.(fs.Block)
		if ok {
			collect = append(collect, b)
		}

		return true
	})

	matched := false
	for _, block := range collect {
		if block.Info().Strong == "d1f11a93449fa4d3f320234743204ce157bbf1f3" {
			matched = true
		}
	}

	assert.Tf(t, matched, "Failed to find expected block")
}
示例#30
0
func DoTestDirDescent(t *testing.T, repo fs.NodeRepo) {
	tg := treegen.New()
	treeSpec := tg.D("foo",
		tg.F("baobab", tg.B(91, 65537)),
		tg.D("bar",
			tg.D("aleph",
				tg.F("a", tg.B(42, 65537)))),
		tg.F("bar3003", tg.B(777, 65537)))

	path := treegen.TestTree(t, treeSpec)
	defer os.RemoveAll(path)

	dir, errors := fs.IndexDir(path, repo)
	assert.Equalf(t, 0, len(errors), "%v", errors)

	for _, fpath := range []string{
		filepath.Join("foo", "baobab"),
		filepath.Join("foo", "bar", "aleph", "a"),
		filepath.Join("foo", "bar3003")} {
		node, found := fs.Lookup(dir, fpath)
		assert.Tf(t, found, "not found: %s", fpath)
		_, isFile := node.(fs.File)
		assert.T(t, isFile)
	}

	node, found := fs.Lookup(dir, filepath.Join("foo", "bar"))
	assert.T(t, found)
	_, isDir := node.(fs.Dir)
	assert.T(t, isDir)
}