Skip to content

Commit

Permalink
Clean up tests and allow the user to define the namespace for tests t…
Browse files Browse the repository at this point in the history
…o run on
  • Loading branch information
khaf committed Aug 16, 2018
1 parent 93bef50 commit 2cbba2e
Show file tree
Hide file tree
Showing 26 changed files with 61 additions and 87 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Change History

<<<<<<< HEAD
## August 3 2018: v1.35.0

* **New Features**
Expand Down
4 changes: 2 additions & 2 deletions aerospike_bench_reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Benchmark_GetObject(b *testing.B) {
b.Fail()
}

key, _ := NewKey("test", "databases", "Aerospike")
key, _ := NewKey(*namespace, "databases", "Aerospike")

obj := &OBJECT{198, "Jack Shaftoe and Company", []int64{1, 2, 3, 4, 5, 6}}
client.PutObject(nil, key, obj)
Expand All @@ -65,7 +65,7 @@ func Benchmark_PutObject(b *testing.B) {

// obj := &OBJECT{198, "Jack Shaftoe and Company", []byte(bytes.Repeat([]byte{32}, 1000))}
obj := &OBJECT{198, "Jack Shaftoe and Company", []int64{1, 2, 3, 4, 5, 6}}
key, _ := NewKey("test", "databases", "Aerospike")
key, _ := NewKey(*namespace, "databases", "Aerospike")
writepolicy := NewWritePolicy(0, 0)

b.N = 100
Expand Down
6 changes: 3 additions & 3 deletions aerospike_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func Benchmark_Get(b *testing.B) {
b.Fail()
}

key, _ := NewKey("test", "test", "Aerospike")
key, _ := NewKey(*namespace, "test", "Aerospike")
// obj := &OBJECT{198, "Jack Shaftoe and Company", []byte(bytes.Repeat([]byte{32}, 1000))}
// obj := &OBJECT{198, "Jack Shaftoe and Company", []int64{1}}
client.Delete(nil, key)
Expand All @@ -86,7 +86,7 @@ func Benchmark_Put(b *testing.B) {
b.Fail()
}

key, _ := NewKey("test", "test", "Aerospike")
key, _ := NewKey(*namespace, "test", "Aerospike")
writepolicy := NewWritePolicy(0, 0)

b.N = 100
Expand All @@ -103,7 +103,7 @@ func Benchmark_BatchGet(b *testing.B) {

var keys []*Key
for i := 0; i < 10; i++ {
key, _ := NewKey("test", "test", i)
key, _ := NewKey(*namespace, "test", i)
if err := client.PutBins(nil, key, NewBin("b", 1)); err == nil {
keys = append(keys, key)
}
Expand Down
23 changes: 13 additions & 10 deletions aerospike_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package aerospike_test

import (
"bytes"
"flag"
"log"
"math/rand"
"os"
"strings"
"testing"
"time"
Expand All @@ -12,6 +14,7 @@ import (
. "github.com/onsi/gomega"

as "github.com/aerospike/aerospike-client-go"
asl "github.com/aerospike/aerospike-client-go/logger"
)

var host = flag.String("h", "127.0.0.1", "Aerospike server seed hostnames or IP addresses")
Expand All @@ -23,6 +26,8 @@ var clientPolicy *as.ClientPolicy
var client *as.Client
var useReplicas = flag.Bool("use-replicas", false, "Aerospike will use replicas as well as master partitions.")

var namespace = flag.String("n", "test", "Namespace")

func initTestVars() {
rand.Seed(time.Now().UnixNano())
flag.Parse()
Expand Down Expand Up @@ -63,11 +68,6 @@ func TestAerospike(t *testing.T) {
}

func featureEnabled(feature string) bool {
client, err := as.NewClientWithPolicy(clientPolicy, *host, *port)
if err != nil {
log.Fatal("Failed to connect to aerospike: err:", err)
}

node := client.GetNodes()[0]
infoMap, err := node.RequestInfo("features")
if err != nil {
Expand All @@ -78,11 +78,6 @@ func featureEnabled(feature string) bool {
}

func nsInfo(ns string, feature string) string {
client, err := as.NewClientWithPolicy(clientPolicy, *host, *port)
if err != nil {
log.Fatal("Failed to connect to aerospike: err:", err)
}

node := client.GetNodes()[0]
infoMap, err := node.RequestInfo("namespace/" + ns)
if err != nil {
Expand All @@ -100,3 +95,11 @@ func nsInfo(ns string, feature string) string {

return ""
}

func init() {
var buf bytes.Buffer
logger := log.New(&buf, "", log.LstdFlags|log.Lshortfile)
logger.SetOutput(os.Stdout)
asl.Logger.SetLogger(logger)
asl.Logger.SetLevel(asl.DEBUG)
}
35 changes: 4 additions & 31 deletions bench_batchget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,34 @@
package aerospike_test

import (
"flag"
"math/rand"
"runtime"
"strings"
"testing"
"time"

_ "net/http/pprof"

. "github.com/aerospike/aerospike-client-go"
)

// var host = flag.String("h", "127.0.0.1", "Aerospike server seed hostnames or IP addresses")
// var port = flag.Int("p", 3000, "Aerospike server seed hostname or IP address port number.")
// var user = flag.String("U", "", "Username.")
// var password = flag.String("P", "", "Password.")
// var clientPolicy *ClientPolicy

var benchClient *Client

func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
rand.Seed(time.Now().UnixNano())
flag.Parse()

clientPolicy = NewClientPolicy()
if *user != "" {
clientPolicy.User = *user
clientPolicy.Password = *password
}

var err error
if benchClient, err = NewClientWithPolicy(clientPolicy, *host, *port); err != nil {
panic(err)
}
}

func makeDataForGetBench(set string, bins []*Bin) {
for i := 0; i < 1000; i++ {
key, _ := NewKey("test", set, i)
benchClient.PutBins(nil, key, bins...)
key, _ := NewKey(*namespace, set, i)
client.PutBins(nil, key, bins...)
}
}

func doGet(policy *BatchPolicy, set string, b *testing.B) {
var err error
var keys []*Key
for i := 0; i < 1000; i++ {
key, _ := NewKey("test", set, i)
key, _ := NewKey(*namespace, set, i)
keys = append(keys, key)
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = benchClient.BatchGet(policy, keys)
_, err = client.BatchGet(policy, keys)
if err != nil {
panic(err)
}
Expand Down
13 changes: 5 additions & 8 deletions bench_cdt_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package aerospike
package aerospike_test

import (
"runtime"
"testing"
// "time"
_ "net/http/pprof"
// . "github.com/aerospike/aerospike-client-go"

. "github.com/aerospike/aerospike-client-go"
)

var list []Value
Expand All @@ -33,7 +34,7 @@ var list []Value
// b.ResetTimer()
// b.SetBytes(0)

// key, _ := NewKey("test", set, 1000)
// key, _ := NewKey(*namespace, set, 1000)

// for i := 0; i < b.N; i++ {
// command := newOperateCommand(nil, policy, key, ops)
Expand All @@ -45,16 +46,14 @@ var list []Value
// }
// }

var client *Client

func doOperate(set string, ops []*Operation, b *testing.B) {
var err error

runtime.GC()
b.ResetTimer()
b.SetBytes(0)

key, _ := NewKey("test", set, 1000)
key, _ := NewKey(*namespace, set, 1000)

for i := 0; i < b.N; i++ {
_, err = client.Operate(nil, key, ops...)
Expand Down Expand Up @@ -105,6 +104,4 @@ func init() {
)
}
list = values

client, _ = NewClient("ubvm", 3000)
}
2 changes: 1 addition & 1 deletion cdt_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("CDT List Test", func() {
}

// connection data
var ns = "test"
var ns = *namespace
var set = randString(50)
var key *as.Key
var wpolicy = as.NewWritePolicy(0, 0)
Expand Down
4 changes: 2 additions & 2 deletions cdt_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var _ = Describe("CDT Map Test", func() {

// connection data
var err error
var ns = "test"
var ns = *namespace
var set = randString(50)
var key *as.Key
var wpolicy = as.NewWritePolicy(0, 0)
Expand Down Expand Up @@ -581,7 +581,7 @@ var _ = Describe("CDT Map Test", func() {
_, err = client.Execute(nil, key, "cdt_tests", "add", as.NewValue("b"), as.NewValue("k"), as.NewValue(1))
Expect(err).ToNot(HaveOccurred())

sets, err := client.ScanAll(nil, "test", "skill")
sets, err := client.ScanAll(nil, ns, "skill")
Expect(err).ToNot(HaveOccurred())

rec, err := client.Get(nil, key)
Expand Down
2 changes: 1 addition & 1 deletion client_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _ = Describe("Aerospike", func() {
Describe("Data operations on objects", func() {
// connection data
var err error
var ns = "test"
var ns = *namespace
var set = randString(50)
var key *as.Key

Expand Down
2 changes: 1 addition & 1 deletion client_reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var _ = Describe("Aerospike", func() {
Describe("Data operations on complex types with reflection", func() {
// connection data
var err error
var ns = "test"
var ns = *namespace
var set = randString(50)
var key *as.Key
var wpolicy = as.NewWritePolicy(0, 0)
Expand Down
10 changes: 5 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var _ = Describe("Aerospike", func() {
Describe("Data operations on native types", func() {
// connection data
var err error
var ns = "test"
var ns = *namespace
var set = randString(50)
var key *as.Key
var wpolicy = as.NewWritePolicy(0, 0)
Expand Down Expand Up @@ -729,7 +729,7 @@ var _ = Describe("Aerospike", func() {
Expect(err).ToNot(HaveOccurred())
})

It("must Delete to a non-existing key", func() {
It("must Delete a non-existing key", func() {
var nxkey *as.Key
nxkey, err = as.NewKey(ns, set, randString(50))
Expect(err).ToNot(HaveOccurred())
Expand All @@ -740,7 +740,7 @@ var _ = Describe("Aerospike", func() {
Expect(existed).To(Equal(false))
})

It("must Delete to an existing key", func() {
It("must Delete an existing key", func() {
var existed bool
existed, err = client.Delete(wpolicy, key)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -761,7 +761,7 @@ var _ = Describe("Aerospike", func() {
Expect(err).ToNot(HaveOccurred())
})

It("must Touch to a non-existing key", func() {
It("must Touch a non-existing key", func() {
var nxkey *as.Key
nxkey, err = as.NewKey(ns, set, randString(50))
Expect(err).ToNot(HaveOccurred())
Expand All @@ -770,7 +770,7 @@ var _ = Describe("Aerospike", func() {
Expect(err).To(HaveOccurred())
})

It("must Touch to an existing key", func() {
It("must Touch an existing key", func() {
rec, err = client.Get(rpolicy, key)
Expect(err).ToNot(HaveOccurred())
generation := rec.Generation
Expand Down
2 changes: 1 addition & 1 deletion complex_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var _ = Describe("Complex Index operations test", func() {
Describe("Complex Index Creation", func() {
// connection data
var err error
var ns = "test"
var ns = *namespace
var set = randString(50)
var key *as.Key
var wpolicy = as.NewWritePolicy(0, 0)
Expand Down
2 changes: 1 addition & 1 deletion complex_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = Describe("Query operations on complex types", func() {
initTestVars()

// connection data
var ns = "test"
var ns = *namespace
var set = randString(50)
var wpolicy = as.NewWritePolicy(0, 0)
wpolicy.SendKey = true
Expand Down
2 changes: 1 addition & 1 deletion geo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var _ = Describe("Geo Spacial Tests", func() {
}

// connection data
var ns = "test"
var ns = *namespace
var set = randString(50)
var wpolicy = as.NewWritePolicy(0, 0)
wpolicy.SendKey = true
Expand Down
2 changes: 1 addition & 1 deletion index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("Index operations test", func() {

Describe("Index creation", func() {
var err error
var ns = "test"
var ns = *namespace
var set = randString(50)
var key *as.Key
var wpolicy = as.NewWritePolicy(0, 0)
Expand Down
2 changes: 1 addition & 1 deletion load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func init() {
// ALL tests are isolated by SetName and Key, which are 50 random characters
var _ = Describe("Aerospike load tests", func() {
Describe("Single long random string test", func() {
var ns = "test"
var ns = *namespace
var set = "load"
var wpolicy = as.NewWritePolicy(0, 0)
var rpolicy = as.NewPolicy()
Expand Down
6 changes: 3 additions & 3 deletions performance/bench_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func init() {
}

func makeDataForGetBench(set string, bins []*Bin) {
key, _ := NewKey("test", set, 0)
key, _ := NewKey(*namespace, set, 0)
benchClient.PutBins(nil, key, bins...)
}

func doGet(set string, b *testing.B) {
var err error
key, _ := NewKey("test", set, 0)
key, _ := NewKey(*namespace, set, 0)
for i := 0; i < b.N; i++ {
_, err = benchClient.Get(nil, key)
if err != nil {
Expand Down Expand Up @@ -172,7 +172,7 @@ func Benchmark_Get_Complex_Map(b *testing.B) {

func doPut(set string, value interface{}, b *testing.B) {
var err error
// key, _ := NewKey("test", set, 0)
// key, _ := NewKey(*namespace, set, 0)
for i := 0; i < b.N; i++ {
bin := NewBin("b", value)
// err = benchClient.PutBins(nil, key, bin)
Expand Down
Loading

0 comments on commit 2cbba2e

Please sign in to comment.