diff --git a/Makefile b/Makefile index a803d88e..d80d1c4b 100644 --- a/Makefile +++ b/Makefile @@ -404,8 +404,8 @@ test: test-clean gotestsum $(BUILD_PROPS) ## Run the unit tests # ---------------------------------------------------------------------------------------------------------------------- .PHONY: test-e2e-standalone test-e2e-standalone: test-clean test gotestsum $(BUILD_PROPS) ## Run e2e tests with Coherence - CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/go-client-test.xml \ - -- $(GO_TEST_FLAGS) -v -coverprofile=$(COVERAGE_DIR)/cover-functional.out -v ./test/e2e/standalone/... -coverpkg=github.com/oracle/coherence-go-client/v2/coherence/... + cd test && CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/go-client-test.xml \ + -- $(GO_TEST_FLAGS) -v -coverprofile=$(COVERAGE_DIR)/cover-functional.out -v ./e2e/standalone/... -coverpkg=github.com/oracle/coherence-go-client/v2/coherence/... go tool cover -func=$(COVERAGE_DIR)/cover-functional.out | grep -v '0.0%' # ---------------------------------------------------------------------------------------------------------------------- @@ -413,16 +413,16 @@ test-e2e-standalone: test-clean test gotestsum $(BUILD_PROPS) ## Run e2e tests w # ---------------------------------------------------------------------------------------------------------------------- .PHONY: test-e2e-streaming test-e2e-streaming: test-clean test gotestsum $(BUILD_PROPS) ## Run e2e tests with Coherence - CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/go-streaming-test.xml \ - -- $(GO_TEST_FLAGS) -v -coverprofile=$(COVERAGE_DIR)/cover-functional.out -v ./test/e2e/streaming/... -coverpkg=github.com/oracle/coherence-go-client/v2/coherence/... + cd test && CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/go-streaming-test.xml \ + -- $(GO_TEST_FLAGS) -v -coverprofile=$(COVERAGE_DIR)/cover-functional.out -v ./e2e/streaming/... -coverpkg=github.com/oracle/coherence-go-client/v2/coherence/... # ---------------------------------------------------------------------------------------------------------------------- # Executes the Go end to end tests for standalone Coherence with Scope set # ---------------------------------------------------------------------------------------------------------------------- .PHONY: test-e2e-standalone-scope test-e2e-standalone-scope: test-clean test gotestsum $(BUILD_PROPS) ## Run e2e tests with Coherence with Scope set - CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/go-client-test-scope.xml \ - -- $(GO_TEST_FLAGS) -v -coverprofile=$(COVERAGE_DIR)/cover-functional-scope.out -v ./test/e2e/scope/... -coverpkg=github.com/oracle/coherence-go-client/v2/coherence/... + cd test && CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/go-client-test-scope.xml \ + -- $(GO_TEST_FLAGS) -v -coverprofile=$(COVERAGE_DIR)/cover-functional-scope.out -v ./e2e/scope/... -coverpkg=github.com/oracle/coherence-go-client/v2/coherence/... go tool cover -func=$(COVERAGE_DIR)/cover-functional-scope.out | grep -v '0.0%' # ---------------------------------------------------------------------------------------------------------------------- @@ -430,8 +430,8 @@ test-e2e-standalone-scope: test-clean test gotestsum $(BUILD_PROPS) ## Run e2e t # ---------------------------------------------------------------------------------------------------------------------- .PHONY: test-e2e-standalone-queues test-e2e-standalone-queues: test-clean test gotestsum $(BUILD_PROPS) ## Run e2e tests with Coherence queues - CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/go-client-test-queues.xml \ - -- $(GO_TEST_FLAGS) -v -coverprofile=$(COVERAGE_DIR)/cover-functional-queues.out -v ./test/e2e/queues/... -coverpkg=github.com/oracle/coherence-go-client/v2/coherence/... + cd test && CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/go-client-test-queues.xml \ + -- $(GO_TEST_FLAGS) -v -coverprofile=$(COVERAGE_DIR)/cover-functional-queues.out -v ./e2e/queues/... -coverpkg=github.com/oracle/coherence-go-client/v2/coherence/... go tool cover -func=$(COVERAGE_DIR)/cover-functional-queues.out | grep -v '0.0%' # ---------------------------------------------------------------------------------------------------------------------- @@ -439,8 +439,8 @@ test-e2e-standalone-queues: test-clean test gotestsum $(BUILD_PROPS) ## Run e2e # ---------------------------------------------------------------------------------------------------------------------- .PHONY: test-v1-base test-v1-base: test-clean test gotestsum $(BUILD_PROPS) ## Run e2e tests with Coherence - CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/go-client-test-v1.xml \ - -- $(GO_TEST_FLAGS) -v -coverprofile=$(COVERAGE_DIR)/cover-functional-v1.out -v ./test/v1/base/... -coverpkg=github.com/oracle/coherence-go-client/v2/coherence/... + cd test && CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/go-client-test-v1.xml \ + -- $(GO_TEST_FLAGS) -v -coverprofile=$(COVERAGE_DIR)/cover-functional-v1.out -v ./v1/base/... -coverpkg=github.com/oracle/coherence-go-client/v2/coherence/... go tool cover -func=$(COVERAGE_DIR)/cover-functional-v1.out | grep -v '0.0%' # ---------------------------------------------------------------------------------------------------------------------- @@ -516,8 +516,8 @@ test-clean: gotestsum ## Clean the go test cache test-discovery: test-clean gotestsum $(BUILD_PROPS) ## Run Discovery tests with Coherence make test-coherence-shutdown || true make test-coherence-startup - CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/cohctl-test-discovery.xml \ - -- $(GO_TEST_FLAGS) -v ./test/e2e/discovery/... + cd test && CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/cohctl-test-discovery.xml \ + -- $(GO_TEST_FLAGS) -v ./e2e/discovery/... make test-coherence-shutdown # ---------------------------------------------------------------------------------------------------------------------- @@ -528,8 +528,8 @@ test-perf: test-clean gotestsum $(BUILD_PROPS) ## Run Discovery tests with Coher ./scripts/perf-cluster.sh $(TEST_LOGS_DIR)/cli $(COHERENCE_VERSION) stop || true mkdir -p $(TEST_LOGS_DIR)/cli ./scripts/perf-cluster.sh $(TEST_LOGS_DIR)/cli $(COHERENCE_VERSION) start - CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/cohctl-test-perf.xml \ - -- $(GO_TEST_FLAGS) -v ./test/e2e/perf/... + cd test && CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/cohctl-test-perf.xml \ + -- $(GO_TEST_FLAGS) -v ./e2e/perf/... ./scripts/perf-cluster.sh $(TEST_LOGS_DIR)/cli $(COHERENCE_VERSION) stop || true rm -rf $(TEST_LOGS_DIR)/cli/* @@ -538,8 +538,8 @@ test-perf: test-clean gotestsum $(BUILD_PROPS) ## Run Discovery tests with Coher # ---------------------------------------------------------------------------------------------------------------------- .PHONY: test-resolver test-resolver: test-clean gotestsum $(BUILD_PROPS) ## Run Resolver tests with Coherence - COHERENCE_RESOLVER_DEBUG=true CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/cohctl-test-resover.xml \ - -- $(GO_TEST_FLAGS) -v ./test/e2e/resolver/... + cd test && COHERENCE_RESOLVER_DEBUG=true CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/cohctl-test-resover.xml \ + -- $(GO_TEST_FLAGS) -v ./e2e/resolver/... # ---------------------------------------------------------------------------------------------------------------------- # Executes the Go resolver cluster tests for standalone Coherence @@ -548,8 +548,8 @@ test-resolver: test-clean gotestsum $(BUILD_PROPS) ## Run Resolver tests with Co test-resolver-cluster: test-clean gotestsum $(BUILD_PROPS) ## Run Resolver tests with Coherence make test-coherence-shutdown || true make test-coherence-startup - COHERENCE_RESOLVER_DEBUG=true CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/cohctl-test-resover-cluster.xml \ - -- $(GO_TEST_FLAGS) -v ./test/e2e/resolver_cluster/... + cd test && COHERENCE_RESOLVER_DEBUG=true CGO_ENABLED=0 $(GOTESTSUM) --format testname --junitfile $(TEST_LOGS_DIR)/cohctl-test-resover-cluster.xml \ + -- $(GO_TEST_FLAGS) -v ./e2e/resolver_cluster/... make test-coherence-shutdown # ---------------------------------------------------------------------------------------------------------------------- diff --git a/coherence/coherence_test_helpers.go b/coherence/coherence_test_helpers.go index 3bd6a393..9574cbc3 100644 --- a/coherence/coherence_test_helpers.go +++ b/coherence/coherence_test_helpers.go @@ -13,111 +13,135 @@ import ( "time" ) -// test helpers +// test helpers only for internal use only. +// TestEnsureCache is only exported for integration tests, not for general use. func TestEnsureCache(ctx context.Context, session *Session, cache string) (*int32, error) { return session.v1StreamManagerCache.ensureCache(ctx, cache) } +// TestClearCache is only exported for integration tests, not for general use. func TestClearCache(ctx context.Context, session *Session, cache string) error { return session.v1StreamManagerCache.clearCache(ctx, cache) } +// TestRemoveMapping is only exported for integration tests, not for general use. func TestRemoveMapping(ctx context.Context, session *Session, cache string, key []byte, value []byte) (bool, error) { return session.v1StreamManagerCache.removeMapping(ctx, cache, key, value) } +// TestReplaceMapping is only exported for integration tests, not for general use. func TestReplaceMapping(ctx context.Context, session *Session, cache string, key []byte, prevValue []byte, newValue []byte) (bool, error) { return session.v1StreamManagerCache.replaceMapping(ctx, cache, key, prevValue, newValue) } +// TestReplace is only exported for integration tests, not for general use. func TestReplace(ctx context.Context, session *Session, cache string, key []byte, value []byte) (*[]byte, error) { return session.v1StreamManagerCache.replace(ctx, cache, key, value) } +// TestTruncateCache is only exported for integration tests, not for general use. func TestTruncateCache(ctx context.Context, session *Session, cache string) error { return session.v1StreamManagerCache.truncateCache(ctx, cache) } +// TestDestroyCache is only exported for integration tests, not for general use. func TestDestroyCache(ctx context.Context, session *Session, cache string) error { return session.v1StreamManagerCache.destroyCache(ctx, cache) } +// TestSize is only exported for integration tests, not for general use. func TestSize(ctx context.Context, session *Session, cache string) (int32, error) { return session.v1StreamManagerCache.size(ctx, cache) } +// TestIsEmpty is only exported for integration tests, not for general use. func TestIsEmpty(ctx context.Context, session *Session, cache string) (bool, error) { return session.v1StreamManagerCache.isEmpty(ctx, cache) } +// TestIsReady is only exported for integration tests, not for general use. func TestIsReady(ctx context.Context, session *Session, cache string) (bool, error) { return session.v1StreamManagerCache.isReady(ctx, cache) } +// TestContainsKey is only exported for integration tests, not for general use. func TestContainsKey(ctx context.Context, session *Session, cache string, key []byte) (bool, error) { return session.v1StreamManagerCache.containsKey(ctx, cache, key) } +// TestContainsValue is only exported for integration tests, not for general use. func TestContainsValue(ctx context.Context, session *Session, cache string, value []byte) (bool, error) { return session.v1StreamManagerCache.containsValue(ctx, cache, value) } +// TestContainsEntry is only exported for integration tests, not for general use. func TestContainsEntry(ctx context.Context, session *Session, cache string, key []byte, value []byte) (bool, error) { return session.v1StreamManagerCache.containsEntry(ctx, cache, key, value) } +// TestGet is only exported for integration tests, not for general use. func TestGet(ctx context.Context, session *Session, cache string, key []byte) (*[]byte, error) { return session.v1StreamManagerCache.get(ctx, cache, key) } +// TestGetAll is only exported for integration tests, not for general use. func TestGetAll(ctx context.Context, session *Session, cache string, keys [][]byte) (<-chan BinaryKeyAndValue, error) { return session.v1StreamManagerCache.getAll(ctx, cache, keys) } +// TestKeyAndValuePage is only exported for integration tests, not for general use. func TestKeyAndValuePage(ctx context.Context, session *Session, cache string, cookie []byte) (<-chan BinaryKeyAndValue, error) { return session.v1StreamManagerCache.keyAndValuePage(ctx, cache, cookie) } +// TestPut is only exported for integration tests, not for general use. func TestPut(ctx context.Context, session *Session, cache string, key []byte, value []byte, ttl time.Duration) (*[]byte, error) { return session.v1StreamManagerCache.put(ctx, cache, key, value, ttl) } +// TestPutAll is only exported for integration tests, not for general use. func TestPutAll(ctx context.Context, session *Session, cache string, entries []*pb1.BinaryKeyAndValue, ttl time.Duration) error { return session.v1StreamManagerCache.putAll(ctx, cache, entries, ttl) } +// TestRemove is only exported for integration tests, not for general use. func TestRemove(ctx context.Context, session *Session, cache string, key []byte) (*[]byte, error) { return session.v1StreamManagerCache.remove(ctx, cache, key) } +// TestPutIfAbsent is only exported for integration tests, not for general use. func TestPutIfAbsent(ctx context.Context, session *Session, cache string, key []byte, value []byte) (*[]byte, error) { return session.v1StreamManagerCache.putIfAbsent(ctx, cache, key, value) } +// TestAggregate is only exported for integration tests, not for general use. func TestAggregate(ctx context.Context, session *Session, cache string, agent []byte, keysOrFilter *pb1.KeysOrFilter) (*[]byte, error) { return session.v1StreamManagerCache.aggregate(ctx, cache, agent, keysOrFilter) } +// TestInvoke is only exported for integration tests, not for general use. func TestInvoke(ctx context.Context, session *Session, cache string, agent []byte, keysOrFilter *pb1.KeysOrFilter) (<-chan BinaryKeyAndValue, error) { return session.v1StreamManagerCache.invoke(ctx, cache, agent, keysOrFilter) } +// TestMapListenerRequest is only exported for integration tests, not for general use. func TestMapListenerRequest(ctx context.Context, session *Session, cache string, subscribe bool, keyOrFilter *pb1.KeyOrFilter, lite bool, synchronous bool, priming bool, filterID int64) error { return session.v1StreamManagerCache.mapListenerRequest(ctx, cache, subscribe, keyOrFilter, lite, synchronous, priming, filterID) } -// GetSessionCacheID returns the cache id for a cache name +// GetSessionCacheID is only exported for integration tests, not for general use. func GetSessionCacheID(session *Session, cache string) *int32 { return session.getCacheID(cache) } -// GetSessionQueueID returns the queue id for a cache name +// GetSessionQueueID is only exported for integration tests, not for general use. func GetSessionQueueID(session *Session, queue string) *int32 { return session.getQueueID(queue) } +// GetNearCachePruneFactor is only exported for integration tests, not for general use. func GetNearCachePruneFactor[K comparable, V any](namedMap NamedMap[K, V]) float32 { ncOptions := namedMap.getBaseClient().cacheOpts.NearCacheOptions if ncOptions == nil { @@ -128,11 +152,13 @@ func GetNearCachePruneFactor[K comparable, V any](namedMap NamedMap[K, V]) float } // revive:disable:unexported-return +// GetKeyListenerGroupMap is only exported for integration tests, not for general use. func GetKeyListenerGroupMap[K comparable, V any](namedMap NamedMap[K, V]) map[K]*listenerGroupV1[K, V] { return namedMap.getBaseClient().keyListenersV1 } // revive:disable:unexported-return +// GetKeyListenerGroupListeners is only exported for integration tests, not for general use. func GetKeyListenerGroupListeners[K comparable, V any](namedMap NamedMap[K, V], key K) []MapListener[K, V] { mapListeners := make([]MapListener[K, V], 0) listenerGroupMap := GetKeyListenerGroupMap[K, V](namedMap) @@ -146,10 +172,12 @@ func GetKeyListenerGroupListeners[K comparable, V any](namedMap NamedMap[K, V], } // revive:disable:unexported-return +// GetFilterListenerGroupMap is only exported for integration tests, not for general use. func GetFilterListenerGroupMap[K comparable, V any](namedMap NamedMap[K, V]) map[filters.Filter]*listenerGroupV1[K, V] { return namedMap.getBaseClient().filterListenersV1 } +// GetFilterListenerGroupListeners is only exported for integration tests, not for general use. func GetFilterListenerGroupListeners[K comparable, V any](namedMap NamedMap[K, V], f filters.Filter) []MapListener[K, V] { mapListeners := make([]MapListener[K, V], 0) listenerGroupMap := GetFilterListenerGroupMap[K, V](namedMap) @@ -161,11 +189,3 @@ func GetFilterListenerGroupListeners[K comparable, V any](namedMap NamedMap[K, V return mapListeners } - -func GetCacheServiceProtocol() V1ProxyProtocol { - return cacheServiceProtocol -} - -func NewEnsureCacheRequest(session *Session, cache string) (*pb1.ProxyRequest, error) { - return session.v1StreamManagerCache.newEnsureCacheRequest(cache) -} diff --git a/coherence/discovery/nslookup_test.go b/coherence/discovery/nslookup_test.go index c79a4438..dd606145 100644 --- a/coherence/discovery/nslookup_test.go +++ b/coherence/discovery/nslookup_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2024 Oracle and/or its affiliates. + * Copyright (c) 2021, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -7,41 +7,52 @@ package discovery import ( - "github.com/onsi/gomega" "testing" ) var defaultTimeout int32 = 30 func TestInvalidHostIp(t *testing.T) { - g := gomega.NewGomegaWithT(t) - _, err := Open("host:123:123", defaultTimeout) - g.Expect(err).To(gomega.Not(gomega.BeNil())) + ensureFails(t, err) _, err = Open("host:1233f", defaultTimeout) - g.Expect(err).To(gomega.Not(gomega.BeNil())) + ensureFails(t, err) _, err = Open("host:-1", defaultTimeout) - g.Expect(err).To(gomega.Not(gomega.BeNil())) + ensureFails(t, err) _, err = Open("host:1023", defaultTimeout) - g.Expect(err).To(gomega.Not(gomega.BeNil())) + ensureFails(t, err) _, err = Open("host:65536", defaultTimeout) - g.Expect(err).To(gomega.Not(gomega.BeNil())) + ensureFails(t, err) +} + +func ensureFails(t *testing.T, err error) { + if err == nil { + t.Errorf("err was nil but should have failed") + } } func TestParseResults(t *testing.T) { - g := gomega.NewGomegaWithT(t) - g.Expect(len(parseResults(""))).To(gomega.Equal(0)) - g.Expect(len(parseResults("[123]"))).To(gomega.Equal(1)) - g.Expect(len(parseResults("[123, 123]"))).To(gomega.Equal(2)) - g.Expect(len(parseResults("[123, 123, 456]"))).To(gomega.Equal(3)) + assertEquals(t, len(parseResults("")), 0) + assertEquals(t, len(parseResults("[123]")), 1) + assertEquals(t, len(parseResults("[123, 123]")), 2) + assertEquals(t, len(parseResults("[123, 123, 456]")), 3) + result := parseResults("[A, BB, CCC]") - g.Expect(len(result)).To(gomega.Equal(3)) + assertEquals(t, len(result), 3) for _, v := range result { valid := v == "A" || v == "BB" || v == "CCC" - g.Expect(valid).To(gomega.BeTrue()) + if !valid { + t.Errorf("invalid result: %v", v) + } + } +} + +func assertEquals(t *testing.T, actual, expected int) { + if actual != expected { + t.Errorf("actual %d != expected %d", actual, expected) } } diff --git a/coherence/event_test.go b/coherence/event_test.go index f6a32d81..e0209d33 100644 --- a/coherence/event_test.go +++ b/coherence/event_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -7,22 +7,26 @@ package coherence import ( - "github.com/onsi/gomega" "testing" ) func TestEventEmitter(t *testing.T) { - g := gomega.NewWithT(t) - var value = "" + var value string callback := func(a string) { value = a } - emitter := newEventEmitter[string, string]() // string label and string event + emitter := newEventEmitter[string, string]() emitter.on("a", callback) + emitter.emit("a", "event") - g.Expect(value).Should(gomega.Equal("event")) + if value != "event" { + t.Fatalf("expected value to be 'event', got '%s'", value) + } + emitter.emit("a", "event2") - g.Expect(value).Should(gomega.Equal("event2")) + if value != "event2" { + t.Fatalf("expected value to be 'event2', got '%s'", value) + } } diff --git a/coherence/localcache_test.go b/coherence/localcache_test.go index 47455280..5213ce4b 100644 --- a/coherence/localcache_test.go +++ b/coherence/localcache_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Oracle and/or its affiliates. + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -7,7 +7,6 @@ package coherence import ( "fmt" - "github.com/onsi/gomega" "log" "math" "sync" @@ -16,264 +15,362 @@ import ( ) func TestBasicLocalCacheOperations(t *testing.T) { - g := gomega.NewWithT(t) - cache := newLocalCache[int, string]("my-cache-1") - g.Expect(cache.Size()).To(gomega.Equal(0)) + if cache.Size() != 0 { + t.Fatalf("expected size 0, got %d", cache.Size()) + } old := cache.Put(1, "one") - g.Expect(cache.Size()).To(gomega.Equal(1)) - g.Expect(old).To(gomega.BeNil()) + if old != nil { + t.Fatalf("expected nil on first Put, got %v", *old) + } + if cache.Size() != 1 { + t.Fatalf("expected size 1, got %d", cache.Size()) + } value := cache.Get(1) - g.Expect(*value).To(gomega.Equal("one")) + if value == nil || *value != "one" { + t.Fatalf("expected Get(1) to return 'one', got %v", value) + } oldValue := cache.Put(1, "ONE") - g.Expect(*oldValue).To(gomega.Equal("one")) + if oldValue == nil || *oldValue != "one" { + t.Fatalf("expected old value to be 'one', got %v", oldValue) + } oldValue = cache.Remove(1) - g.Expect(*oldValue).To(gomega.Equal("ONE")) - g.Expect(cache.Size()).To(gomega.Equal(0)) + if oldValue == nil || *oldValue != "ONE" { + t.Fatalf("expected removed value to be 'ONE', got %v", oldValue) + } + if cache.Size() != 0 { + t.Fatalf("expected size 0 after removal, got %d", cache.Size()) + } value = cache.Get(1) - g.Expect(value).To(gomega.BeNil()) + if value != nil { + t.Fatalf("expected nil after removal, got %v", *value) + } cache.Put(1, "one") cache.Put(2, "two") cache.Put(3, "three") - g.Expect(cache.Size()).To(gomega.Equal(3)) + if cache.Size() != 3 { + t.Fatalf("expected size 3 after puts, got %d", cache.Size()) + } cache.Clear() - g.Expect(cache.Size()).To(gomega.Equal(0)) + if cache.Size() != 0 { + t.Fatalf("expected size 0 after clear, got %d", cache.Size()) + } - cache.PutWithExpiry(1, "one", time.Duration(3)*time.Second) + cache.PutWithExpiry(1, "one", 3*time.Second) Sleep(4) - g.Expect(cache.Get(1)).To(gomega.BeNil()) - g.Expect(cache.Size()).To(gomega.Equal(0)) + if val := cache.Get(1); val != nil { + t.Fatalf("expected nil after expiry, got %v", *val) + } + if cache.Size() != 0 { + t.Fatalf("expected size 0 after expiry, got %d", cache.Size()) + } - cache.PutWithExpiry(1, "one", time.Duration(3)*time.Second) + cache.PutWithExpiry(1, "one", 3*time.Second) Sleep(4) - g.Expect(cache.Remove(1)).To(gomega.BeNil()) - g.Expect(cache.Size()).To(gomega.Equal(0)) + if val := cache.Remove(1); val != nil { + t.Fatalf("expected nil after expiry on remove, got %v", *val) + } + if cache.Size() != 0 { + t.Fatalf("expected size 0 after expired remove, got %d", cache.Size()) + } - cache.PutWithExpiry(1, "one", time.Duration(3)*time.Second) + cache.PutWithExpiry(1, "one", 3*time.Second) Sleep(4) - g.Expect(cache.Size()).To(gomega.Equal(0)) + if cache.Size() != 0 { + t.Fatalf("expected size 0 after expiry, got %d", cache.Size()) + } - cache.PutWithExpiry(1, "one", time.Duration(257)*time.Millisecond) - time.Sleep(time.Duration(258) * time.Millisecond) - g.Expect(cache.Size()).To(gomega.Equal(0)) + cache.PutWithExpiry(1, "one", 257*time.Millisecond) + time.Sleep(258 * time.Millisecond) + if cache.Size() != 0 { + t.Fatalf("expected size 0 after millisecond expiry, got %d", cache.Size()) + } - g.Expect(len(cache.expiryMap)).To(gomega.Equal(0)) + expiryMap := cache.expiryMap + if len(expiryMap) != 0 { + t.Fatalf("expected expiry map to be empty, got len=%d", len(expiryMap)) + } fmt.Println(cache) } func TestBasicLocalCacheOperationsWithExpiry(t *testing.T) { - g := gomega.NewWithT(t) - cache := newLocalCache[int, string]("my-cache-2") - g.Expect(cache.Size()).To(gomega.Equal(0)) - old := cache.PutWithExpiry(1, "one", time.Duration(1)*time.Second) - g.Expect(cache.Size()).To(gomega.Equal(1)) - g.Expect(old).To(gomega.BeNil()) + if cache.Size() != 0 { + t.Fatalf("expected cache size 0, got %d", cache.Size()) + } + + old := cache.PutWithExpiry(1, "one", time.Second) + if cache.Size() != 1 { + t.Fatalf("expected cache size 1 after first put, got %d", cache.Size()) + } + if old != nil { + t.Fatalf("expected old value to be nil for first key, got %v", old) + } - old = cache.PutWithExpiry(2, "two", time.Duration(1)*time.Second) - g.Expect(cache.Size()).To(gomega.Equal(2)) - g.Expect(old).To(gomega.BeNil()) + old = cache.PutWithExpiry(2, "two", time.Second) + if cache.Size() != 2 { + t.Fatalf("expected cache size 2 after second put, got %d", cache.Size()) + } + if old != nil { + t.Fatalf("expected old value to be nil for second key, got %v", old) + } - // remove one of the entries, cache.Remove(1) - g.Expect(cache.Size()).To(gomega.Equal(1)) + if cache.Size() != 1 { + t.Fatalf("expected cache size 1 after removing key 1, got %d", cache.Size()) + } - // wait for 2 seconds for the other to expire - time.Sleep(time.Duration(2) * time.Second) + time.Sleep(2 * time.Second) - // do a Size() to force expiry - g.Expect(cache.Size()).To(gomega.Equal(0)) + if cache.Size() != 0 { + t.Fatalf("expected cache size 0 after expiry, got %d", cache.Size()) + } - g.Expect(len(cache.expiryMap)).To(gomega.Equal(0)) + if len(cache.expiryMap) != 0 { + t.Fatalf("expected expiry map to be empty, got %d entries", len(cache.expiryMap)) + } fmt.Println(cache) } func TestBasicLocalCacheWithDefaultExpiry(t *testing.T) { - g := gomega.NewWithT(t) + cache := newLocalCache[int, string]("my-cache", withLocalCacheExpiry(2*time.Second)) - cache := newLocalCache[int, string]("my-cache", withLocalCacheExpiry(time.Duration(2)*time.Second)) - g.Expect(cache.Size()).To(gomega.Equal(0)) + if cache.Size() != 0 { + t.Fatalf("expected cache size 0 initially, got %d", cache.Size()) + } cache.Put(1, "one") - g.Expect(cache.Size()).To(gomega.Equal(1)) - Sleep(3) - g.Expect(cache.Size()).To(gomega.Equal(0)) + if cache.Size() != 1 { + t.Fatalf("expected cache size 1 after put, got %d", cache.Size()) + } + + Sleep(3) // assuming this is a helper that sleeps for 3 seconds + + if cache.Size() != 0 { + t.Fatalf("expected cache size 0 after expiry, got %d", cache.Size()) + } } func TestBasicLocalCacheClear(t *testing.T) { - g := gomega.NewWithT(t) + cache := newLocalCache[int, string]("my-cache-clear", withLocalCacheExpiry(2*time.Second)) - cache := newLocalCache[int, string]("my-cache-clear", withLocalCacheExpiry(time.Duration(2)*time.Second)) - g.Expect(cache.Size()).To(gomega.Equal(0)) + if cache.Size() != 0 { + t.Fatalf("expected cache size 0 initially, got %d", cache.Size()) + } cache.Put(1, "one") - g.Expect(cache.Size()).To(gomega.Equal(1)) + + if cache.Size() != 1 { + t.Fatalf("expected cache size 1 after put, got %d", cache.Size()) + } + cache.Clear() - g.Expect(cache.Size()).To(gomega.Equal(0)) + if cache.Size() != 0 { + t.Fatalf("expected cache size 0 after clear, got %d", cache.Size()) + } } func TestBasicLocalCacheRelease(t *testing.T) { - g := gomega.NewWithT(t) + cache := newLocalCache[int, string]("my-cache-clear", withLocalCacheExpiry(2*time.Second)) - cache := newLocalCache[int, string]("my-cache-clear", withLocalCacheExpiry(time.Duration(2)*time.Second)) - g.Expect(cache.Size()).To(gomega.Equal(0)) + if cache.Size() != 0 { + t.Fatalf("expected cache size 0 initially, got %d", cache.Size()) + } cache.Put(1, "one") - g.Expect(cache.Size()).To(gomega.Equal(1)) + + if cache.Size() != 1 { + t.Fatalf("expected cache size 1 after put, got %d", cache.Size()) + } + cache.Release() - g.Expect(cache.Size()).To(gomega.Equal(0)) + if cache.Size() != 0 { + t.Fatalf("expected cache size 0 after release, got %d", cache.Size()) + } } func TestBasicLocalCacheGetAll(t *testing.T) { - g := gomega.NewWithT(t) + cache := newLocalCache[int, string]("my-cache-get-all", withLocalCacheExpiry(10*time.Second)) - cache := newLocalCache[int, string]("my-cache-get-all", withLocalCacheExpiry(time.Duration(10)*time.Second)) - g.Expect(cache.Size()).To(gomega.Equal(0)) - g.Expect(len(cache.GetAll([]int{1, 2, 3}))).To(gomega.Equal(0)) + if cache.Size() != 0 { + t.Fatalf("expected cache size 0 initially, got %d", cache.Size()) + } + + results := cache.GetAll([]int{1, 2, 3}) + if len(results) != 0 { + t.Fatalf("expected empty result from GetAll, got %d", len(results)) + } cache.Put(1, "one") cache.Put(2, "two") cache.Put(3, "three") cache.Put(4, "four") cache.Put(5, "five") - g.Expect(cache.Size()).To(gomega.Equal(5)) - results := cache.GetAll([]int{1, 5}) - g.Expect(len(results)).To(gomega.Equal(2)) + if cache.Size() != 5 { + t.Fatalf("expected cache size 5 after puts, got %d", cache.Size()) + } + + results = cache.GetAll([]int{1, 5}) + if len(results) != 2 { + t.Fatalf("expected 2 results, got %d", len(results)) + } v, ok := results[1] - g.Expect(ok).To(gomega.Equal(true)) - g.Expect(*v).To(gomega.Equal("one")) + if !ok || v == nil || *v != "one" { + t.Fatalf("expected results[1] to be 'one', got %v", v) + } v, ok = results[5] - g.Expect(ok).To(gomega.Equal(true)) - g.Expect(*v).To(gomega.Equal("five")) + if !ok || v == nil || *v != "five" { + t.Fatalf("expected results[5] to be 'five', got %v", v) + } v, ok = results[6] - g.Expect(ok).To(gomega.Equal(false)) - g.Expect(v).To(gomega.BeNil()) + if ok || v != nil { + t.Fatalf("expected results[6] to be nil/missing, got %v", v) + } } func TestLocalCacheWithHighUnitsOnly(t *testing.T) { - g := gomega.NewWithT(t) - cache := newLocalCache[int, string]("my-cache-high-unit1", withLocalCacheHighUnits(100)) for i := 0; i < 100; i++ { cache.Put(i, fmt.Sprintf("value-%v", i)) } - g.Expect(cache.Size()).To(gomega.Equal(100)) + if cache.Size() != 100 { + t.Fatalf("expected size 100 after inserts, got %d", cache.Size()) + } - // put a new entry which should cause prune of 20 entries cache.Put(100, "one hundred") expectedSize := int(math.Round(float64(float32(100) * cache.options.PruneFactor))) + if cache.Size() != expectedSize { + t.Fatalf("expected size %d after prune, got %d", expectedSize, cache.Size()) + } + + if cache.GetCachePrunes() != 1 { + t.Fatalf("expected 1 cache prune, got %d", cache.GetCachePrunes()) + } - g.Expect(cache.Size()).To(gomega.Equal(expectedSize)) - g.Expect(cache.GetCachePrunes()).To(gomega.Equal(int64(1))) fmt.Println(cache) } func TestLocalCacheWithHighUnitsMemoryOnly(t *testing.T) { - g := gomega.NewWithT(t) - cache := newLocalCache[int, string]("my-cache-high-unit2", withLocalCacheHighUnitsMemory(1024*100)) for i := 0; i < 10_000; i++ { cache.Put(i, fmt.Sprintf("value2-%v", i)) } - // cache size should be less than 10,000 as it would not all fit in under 100K - g.Expect(cache.Size() < 10_000).To(gomega.Equal(true)) + if cache.Size() >= 10_000 { + t.Fatalf("expected cache size to be less than 10,000 due to memory constraints, got %d", cache.Size()) + } fmt.Println(cache) } func TestLocalCacheWithHighUnitsOnlyAccessTime(t *testing.T) { - g := gomega.NewWithT(t) - cache := newLocalCache[int, string]("my-cache-high-unit3", withLocalCacheHighUnits(100)) for i := 0; i < 100; i++ { cache.Put(i, fmt.Sprintf("value3-%v", i)) } - g.Expect(cache.Size()).To(gomega.Equal(100)) + if cache.Size() != 100 { + t.Fatalf("expected cache size 100 after inserts, got %d", cache.Size()) + } - // access key 1, 2 and 3, when we prune we should not see these entries be removed - // as they were most recently accessed + // access keys to make them recently used cache.Get(1) cache.Get(2) cache.Get(3) - time.Sleep(time.Duration(5) * time.Second) - // put a new entry which should cause prune of 20 entries + time.Sleep(5 * time.Second) + + // add new entry to trigger prune cache.Put(100, "one hundred") expectedSize := int(math.Round(float64(float32(100) * cache.options.PruneFactor))) + if cache.Size() != expectedSize { + t.Fatalf("expected cache size %d after prune, got %d", expectedSize, cache.Size()) + } - g.Expect(cache.Size()).To(gomega.Equal(expectedSize)) - g.Expect(cache.GetCachePrunes()).To(gomega.Equal(int64(1))) + if cache.GetCachePrunes() != 1 { + t.Fatalf("expected 1 prune operation, got %d", cache.GetCachePrunes()) + } - // entries 1, 2 and three should not be removed as they were accessed - g.Expect(cache.Get(1)).To(gomega.Not(gomega.BeNil())) - g.Expect(cache.Get(2)).To(gomega.Not(gomega.BeNil())) - g.Expect(cache.Get(3)).To(gomega.Not(gomega.BeNil())) + // accessed entries should still be present + if cache.Get(1) == nil { + t.Fatalf("expected key 1 to be present after prune") + } + if cache.Get(2) == nil { + t.Fatalf("expected key 2 to be present after prune") + } + if cache.Get(3) == nil { + t.Fatalf("expected key 3 to be present after prune") + } } func TestLocalCacheWithHighUnitsAndTTL(t *testing.T) { - g := gomega.NewWithT(t) - - cache := newLocalCache[int, string]("my-cache-high-unit", withLocalCacheHighUnits(100), withLocalCacheExpiry(time.Duration(2)*time.Second)) + cache := newLocalCache[int, string]( + "my-cache-high-unit", + withLocalCacheHighUnits(100), + withLocalCacheExpiry(2*time.Second), + ) for i := 0; i < 100; i++ { cache.Put(i, fmt.Sprintf("value-%v", i)) } - g.Expect(cache.Size()).To(gomega.Equal(100)) + if cache.Size() != 100 { + t.Fatalf("expected cache size 100 after inserts, got %d", cache.Size()) + } - // sleep for 1 second and add a new entry, entries should not be expired - time.Sleep(time.Duration(1) * time.Second) + time.Sleep(1 * time.Second) cache.Put(100, "one hundred") cache.Put(101, "one hundred and one") - g.Expect(cache.Size()).To(gomega.Equal(81)) - g.Expect(cache.Get(100)).To(gomega.Not(gomega.BeNil())) - g.Expect(cache.Get(101)).To(gomega.Not(gomega.BeNil())) + if cache.Size() != 81 { + t.Fatalf("expected cache size 81 after prune, got %d", cache.Size()) + } + if cache.Get(100) == nil { + t.Fatalf("expected key 100 to exist") + } + if cache.Get(101) == nil { + t.Fatalf("expected key 101 to exist") + } - time.Sleep(time.Duration(2) * time.Second) - // put 20 new entries, all the entries, all entries < 100 should be expired + time.Sleep(2 * time.Second) for i := 110; i < 130; i++ { cache.Put(i, fmt.Sprintf("value-%v", i)) } - g.Expect(cache.Size()).To(gomega.Equal(20)) + if cache.Size() != 20 { + t.Fatalf("expected cache size 20 after TTL expiry and new inserts, got %d", cache.Size()) + } fmt.Println(cache) } - func TestLocalCacheGoRoutines(t *testing.T) { - var ( - g = gomega.NewWithT(t) - cache = newLocalCache[int, string]("my-cache-2") - wg sync.WaitGroup - ) + cache := newLocalCache[int, string]("my-cache-2") + var wg sync.WaitGroup routines := 500 iterations := 10_000 @@ -291,47 +388,60 @@ func TestLocalCacheGoRoutines(t *testing.T) { wg.Wait() fmt.Println("End " + time.Now().String()) + size := cache.Size() + expected := routines * iterations - g.Expect(size).To(gomega.Equal(routines * iterations)) + if size != expected { + t.Fatalf("expected cache size %d, got %d", expected, size) + } fmt.Println(cache.GetStats()) } func TestBasicLocalCacheSizeCalculation(t *testing.T) { - g := gomega.NewWithT(t) const maxEntries = 10_000 - cache := newLocalCache[int, string]("my-size-calc-size") - g.Expect(cache.Size()).To(gomega.Equal(0)) - // add maxEntries entries, this should update the memory + if cache.Size() != 0 { + t.Fatalf("expected initial cache size 0, got %d", cache.Size()) + } + + // Add entries for i := 1; i <= maxEntries; i++ { cache.Put(i, fmt.Sprintf("value-%v", i)) } - // we should still have memory used - g.Expect(cache.cacheMemory > 0).To(gomega.BeTrue()) + if cache.cacheMemory <= 0 { + t.Fatal("expected memory usage to be greater than 0 after initial put") + } - // update maxEntries entries with a bigger value, this should update the memory with the delta of the new-old + // Update entries with bigger values for i := 1; i <= maxEntries; i++ { cache.Put(i, fmt.Sprintf("new-value-bigger-%v", i)) } - g.Expect(cache.cacheMemory > 0).To(gomega.BeTrue()) - // update maxEntries entries with a smaller value, this should update the memory with the delta of the new-old + if cache.cacheMemory <= 0 { + t.Fatal("expected memory usage to be greater than 0 after updating with bigger values") + } + + // Update entries with smaller values for i := 1; i <= maxEntries; i++ { cache.Put(i, fmt.Sprintf("%v", i)) } - g.Expect(cache.cacheMemory > 0).To(gomega.BeTrue()) - // remove each entry and the local cache size should get back to zero to show that - // the memory calculation is working both ways + if cache.cacheMemory <= 0 { + t.Fatal("expected memory usage to be greater than 0 after updating with smaller values") + } + + // Remove entries and confirm memory is freed for i := 1; i <= maxEntries; i++ { cache.Remove(i) } - g.Expect(cache.cacheMemory).Should(gomega.Equal(int64(0))) + if mem := cache.cacheMemory; mem != 0 { + t.Fatalf("expected memory usage to be 0 after removing entries, got %d", mem) + } } type expiryResults struct { @@ -344,9 +454,6 @@ func TestNearCacheExpiry1(_ *testing.T) { var results = make([]expiryResults, 0) results = append(results, localCacheExpiryTest(time.Duration(1000)*time.Millisecond, 250_000)) - //for ttl = 300; ttl < 1_000; ttl += 300 { - // results = append(results, localCacheExpiryTest(time.Duration(ttl)*time.Millisecond, 1_000_000)) - //} // output results for _, r := range results { @@ -355,13 +462,23 @@ func TestNearCacheExpiry1(_ *testing.T) { } func TestNearCacheBuckets(t *testing.T) { - g := gomega.NewWithT(t) + tests := []struct { + input time.Duration + expected time.Duration + }{ + {254 * time.Millisecond, 0 * time.Millisecond}, + {257 * time.Millisecond, 256 * time.Millisecond}, + {511 * time.Millisecond, 256 * time.Millisecond}, + {513 * time.Millisecond, 512 * time.Millisecond}, + {800 * time.Millisecond, 768 * time.Millisecond}, + } - g.Expect(getMillisBucket(time.Duration(254) * time.Millisecond)).To(gomega.Equal(time.Duration(0) * time.Millisecond)) - g.Expect(getMillisBucket(time.Duration(257) * time.Millisecond)).To(gomega.Equal(time.Duration(256) * time.Millisecond)) - g.Expect(getMillisBucket(time.Duration(511) * time.Millisecond)).To(gomega.Equal(time.Duration(256) * time.Millisecond)) - g.Expect(getMillisBucket(time.Duration(513) * time.Millisecond)).To(gomega.Equal(time.Duration(512) * time.Millisecond)) - g.Expect(getMillisBucket(time.Duration(800) * time.Millisecond)).To(gomega.Equal(time.Duration(768) * time.Millisecond)) + for _, tt := range tests { + actual := getMillisBucket(tt.input) + if actual != tt.expected { + t.Fatalf("GetMillisBucketForTest(%v): expected %v, got %v", tt.input, tt.expected, actual) + } + } } func localCacheExpiryTest(ttl time.Duration, count int) expiryResults { diff --git a/coherence/log_level_test.go b/coherence/log_level_test.go index 07c1d6c6..1a42031e 100644 --- a/coherence/log_level_test.go +++ b/coherence/log_level_test.go @@ -8,8 +8,8 @@ package coherence import ( "bytes" - "github.com/onsi/gomega" "log" + "strings" "testing" ) @@ -46,22 +46,21 @@ func TestErrorLogLevel(t *testing.T) { } func runLogLevelTest(t *testing.T, messageLevel, testLogLevel logLevel, expectOutput bool) { - g := gomega.NewWithT(t) const message = "MESSAGE" - var buf bytes.Buffer origOutput := log.Writer() log.SetOutput(&buf) defer log.SetOutput(origOutput) - setLogLevel(testLogLevel.String()) + setLogLevel(testLogLevel.String()) logMessage(messageLevel, message) output := buf.String() - if expectOutput { - g.Expect(output).To(gomega.ContainSubstring(message)) - } else { - g.Expect(output).To(gomega.Not(gomega.ContainSubstring(message))) + if expectOutput && !strings.Contains(output, message) { + t.Fatalf("expected output to contain %q but it didn't", message) + } + if !expectOutput && strings.Contains(output, message) { + t.Fatalf("expected output to NOT contain %q but it did", message) } } diff --git a/coherence/named_cache_client_test.go b/coherence/named_cache_client_test.go index c3be2aca..0259b7fc 100644 --- a/coherence/named_cache_client_test.go +++ b/coherence/named_cache_client_test.go @@ -1,5 +1,5 @@ /* -* Copyright (c) 2024 Oracle and/or its affiliates. +* Copyright (c) 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -7,7 +7,7 @@ package coherence import ( - "github.com/onsi/gomega" + "errors" "testing" "time" ) @@ -15,7 +15,6 @@ import ( // TestIsNearCacheEqual tests various scenarios where cache options should equal. func TestIsNearCacheEqual(t *testing.T) { var ( - g = gomega.NewWithT(t) nearCacheOptions1 = NearCacheOptions{TTL: time.Duration(10) * time.Second, PruneFactor: 0.8} nearCacheOptions2 = NearCacheOptions{TTL: time.Duration(8) * time.Second, PruneFactor: 0.8} nearCacheOptions3 = NearCacheOptions{HighUnits: 100, PruneFactor: 0.8} @@ -29,22 +28,41 @@ func TestIsNearCacheEqual(t *testing.T) { localCache3 := newLocalCache[int, string]("test", withLocalCacheHighUnitsMemory(10_000)) localCache4 := newLocalCache[int, string]("test", withInvalidationStrategy(ListenAll)) - g.Expect(isNearCacheEqual[int, string](localCache1, &nearCacheOptions1)).To(gomega.Equal(true)) - g.Expect(isNearCacheEqual[int, string](localCache1, &nearCacheOptions2)).To(gomega.Equal(false)) - g.Expect(isNearCacheEqual[int, string](localCache2, &nearCacheOptions2)).To(gomega.Equal(false)) - g.Expect(isNearCacheEqual[int, string](localCache2, &nearCacheOptions3)).To(gomega.Equal(true)) - g.Expect(isNearCacheEqual[int, string](localCache3, &nearCacheOptions3)).To(gomega.Equal(false)) - g.Expect(isNearCacheEqual[int, string](localCache3, &nearCacheOptions4)).To(gomega.Equal(true)) - g.Expect(isNearCacheEqual[int, string](localCache3, &nearCacheOptions4)).To(gomega.Equal(true)) - g.Expect(isNearCacheEqual[int, string](localCache4, &nearCacheOptions4)).To(gomega.Equal(false)) - g.Expect(isNearCacheEqual[int, string](localCache4, &nearCacheOptions5)).To(gomega.Equal(true)) - g.Expect(isNearCacheEqual[int, string](localCache3, &nearCacheOptions6)).To(gomega.Equal(false)) + if !isNearCacheEqual[int, string](localCache1, &nearCacheOptions1) { + t.Fatalf("expected localCache1 to equal nearCacheOptions1") + } + if isNearCacheEqual[int, string](localCache1, &nearCacheOptions2) { + t.Fatalf("expected localCache1 to not equal nearCacheOptions2") + } + if isNearCacheEqual[int, string](localCache2, &nearCacheOptions2) { + t.Fatalf("expected localCache2 to not equal nearCacheOptions2") + } + if !isNearCacheEqual[int, string](localCache2, &nearCacheOptions3) { + t.Fatalf("expected localCache2 to equal nearCacheOptions3") + } + if isNearCacheEqual[int, string](localCache3, &nearCacheOptions3) { + t.Fatalf("expected localCache3 to not equal nearCacheOptions3") + } + if !isNearCacheEqual[int, string](localCache3, &nearCacheOptions4) { + t.Fatalf("expected localCache3 to equal nearCacheOptions4") + } + if !isNearCacheEqual[int, string](localCache3, &nearCacheOptions4) { + t.Fatalf("expected localCache3 to equal nearCacheOptions4") + } + if isNearCacheEqual[int, string](localCache4, &nearCacheOptions4) { + t.Fatalf("expected localCache4 to not equal nearCacheOptions4") + } + if !isNearCacheEqual[int, string](localCache4, &nearCacheOptions5) { + t.Fatalf("expected localCache4 to equal nearCacheOptions5") + } + if isNearCacheEqual[int, string](localCache3, &nearCacheOptions6) { + t.Fatalf("expected localCache3 to not equal nearCacheOptions6") + } } // TestInvalidNearCacheOptions tests various edge cases for near cache options func TestInvalidNearCacheOptions(t *testing.T) { var ( - g = gomega.NewWithT(t) nearCacheOptions1 = NearCacheOptions{HighUnits: -1} nearCacheOptions2 = NearCacheOptions{HighUnitsMemory: -1} nearCacheOptions3 = NearCacheOptions{HighUnitsMemory: 1, HighUnits: 1} @@ -54,20 +72,32 @@ func TestInvalidNearCacheOptions(t *testing.T) { ) err := ensureNearCacheOptions(&nearCacheOptions1) - g.Expect(err).To(gomega.Equal(ErrNegativeNearCacheOptions)) + if !errors.Is(err, ErrNegativeNearCacheOptions) { + t.Fatalf("expected ErrNegativeNearCacheOptions, got: %v", err) + } err = ensureNearCacheOptions(&nearCacheOptions2) - g.Expect(err).To(gomega.Equal(ErrNegativeNearCacheOptions)) + if !errors.Is(err, ErrNegativeNearCacheOptions) { + t.Fatalf("expected ErrNegativeNearCacheOptions, got: %v", err) + } err = ensureNearCacheOptions(&nearCacheOptions3) - g.Expect(err).To(gomega.Equal(ErrInvalidNearCacheWithNoTTL)) + if !errors.Is(err, ErrInvalidNearCacheWithNoTTL) { + t.Fatalf("expected ErrInvalidNearCacheWithNoTTL, got: %v", err) + } err = ensureNearCacheOptions(&nearCacheOptions4) - g.Expect(err).To(gomega.Equal(ErrInvalidNearCacheWithTTL)) + if !errors.Is(err, ErrInvalidNearCacheWithTTL) { + t.Fatalf("expected ErrInvalidNearCacheWithTTL, got: %v", err) + } err = ensureNearCacheOptions(&nearCacheOptions5) - g.Expect(err).To(gomega.Equal(ErrInvalidNearCache)) + if !errors.Is(err, ErrInvalidNearCache) { + t.Fatalf("expected ErrInvalidNearCache, got: %v", err) + } err = ensureNearCacheOptions(&nearCacheOptions7) - g.Expect(err).To(gomega.Equal(ErrInvalidNearCacheTTL)) + if !errors.Is(err, ErrInvalidNearCacheTTL) { + t.Fatalf("expected ErrInvalidNearCacheTTL, got: %v", err) + } } diff --git a/coherence/resolver_test.go b/coherence/resolver_test.go index 5fd4c6a9..4726ab0f 100644 --- a/coherence/resolver_test.go +++ b/coherence/resolver_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Oracle and/or its affiliates. + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -7,45 +7,59 @@ package coherence import ( - "github.com/onsi/gomega" "testing" ) func TestResolverParseNsLookupString(t *testing.T) { - var ( - g = gomega.NewWithT(t) - err error - results []string - ) + checkError := func(err error, shouldFail bool, label string) { + if shouldFail && err == nil { + t.Fatalf("%s: expected error but got nil", label) + } + if !shouldFail && err != nil { + t.Fatalf("%s: unexpected error: %v", label, err) + } + } - _, err = parseNsLookupString("") - g.Expect(err).To(gomega.HaveOccurred()) + checkResults := func(results []string, expected []string, label string) { + if len(results) != len(expected) { + t.Fatalf("%s: expected %d results, got %d", label, len(expected), len(results)) + } + for i := range expected { + if results[i] != expected[i] { + t.Fatalf("%s: expected results[%d] = %s, got %s", label, i, expected[i], results[i]) + } + } + } + + _, err := parseNsLookupString("") + checkError(err, true, "empty input") _, err = parseNsLookupString("[123123123") - g.Expect(err).To(gomega.HaveOccurred()) + checkError(err, true, "missing closing bracket") _, err = parseNsLookupString("123123123]") - g.Expect(err).To(gomega.HaveOccurred()) + checkError(err, true, "missing opening bracket") - results, err = parseNsLookupString("[]") - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(len(results)).To(gomega.Equal(0)) + results, err := parseNsLookupString("[]") + checkError(err, false, "empty array") + checkResults(results, []string{}, "empty array result") results, err = parseNsLookupString("[127.0.0.1, 58193, 127.0.0.1, 58192, 127.0.0.1, 58194]") - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(len(results)).To(gomega.Equal(3)) - g.Expect(results[0]).To(gomega.Equal("127.0.0.1:58193")) - g.Expect(results[1]).To(gomega.Equal("127.0.0.1:58192")) - g.Expect(results[2]).To(gomega.Equal("127.0.0.1:58194")) + checkError(err, false, "multiple pairs") + checkResults(results, []string{ + "127.0.0.1:58193", + "127.0.0.1:58192", + "127.0.0.1:58194", + }, "multiple pairs result") results, err = parseNsLookupString("[127.0.0.1, 58193]") - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(len(results)).To(gomega.Equal(1)) - g.Expect(results[0]).To(gomega.Equal("127.0.0.1:58193")) + checkError(err, false, "single pair") + checkResults(results, []string{"127.0.0.1:58193"}, "single pair result") results, err = parseNsLookupString("[127.0.0.1, 58193, 127.0.0.1, 58192]") - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(len(results)).To(gomega.Equal(2)) - g.Expect(results[0]).To(gomega.Equal("127.0.0.1:58193")) - g.Expect(results[1]).To(gomega.Equal("127.0.0.1:58192")) + checkError(err, false, "two pairs") + checkResults(results, []string{ + "127.0.0.1:58193", + "127.0.0.1:58192", + }, "two pairs result") } diff --git a/coherence/serializers_test.go b/coherence/serializers_test.go index 6bf759ab..15077fdb 100644 --- a/coherence/serializers_test.go +++ b/coherence/serializers_test.go @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022, 2023 Oracle and/or its affiliates. +* Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -7,21 +7,26 @@ package coherence import ( - "github.com/onsi/gomega" + "reflect" "testing" ) func TestInvalidSerializer(t *testing.T) { - g := gomega.NewWithT(t) - - // test that the default format of "json" will always be used serializer := NewSerializer[string]("invalid") serialized, err := serializer.Serialize("AAA") - g.Expect(err).ShouldNot(gomega.HaveOccurred()) + if err != nil { + t.Fatalf("Serialize failed: %v", err) + } + deserialized, err := serializer.Deserialize(serialized) - g.Expect(err).ShouldNot(gomega.HaveOccurred()) - g.Expect(*deserialized).To(gomega.Equal("AAA")) + if err != nil { + t.Fatalf("Deserialize failed: %v", err) + } + + if *deserialized != "AAA" { + t.Fatalf("expected 'AAA', got '%s'", *deserialized) + } } func TestJsonSerializer(t *testing.T) { @@ -35,32 +40,37 @@ func TestJsonSerializer(t *testing.T) { 2: {3, "tim2"}, } - testSerialization[string](t, "hello") - testSerialization[int](t, 123) - testSerialization[float64](t, 123.123) - testSerialization[int64](t, 23) - testSerialization[bool](t, false) - testSerialization[bool](t, true) - testSerialization[byte](t, 1) - testSerialization[[]byte](t, []byte{1, 2, 3, 4}) - testSerialization[person](t, person{ID: 1, Name: "tim"}) - testSerialization[[]string](t, []string{"hello", "hello2", "hello3"}) - testSerialization[[]int](t, []int{12, 12, 12, 4, 4, 4, 3, 5}) - testSerialization[map[int]person](t, myMap) + testSerialization(t, "hello") + testSerialization(t, 123) + testSerialization(t, 123.123) + testSerialization(t, int64(23)) + testSerialization(t, false) + testSerialization(t, true) + testSerialization(t, byte(1)) + testSerialization(t, []byte{1, 2, 3, 4}) + testSerialization(t, person{ID: 1, Name: "tim"}) + testSerialization(t, []string{"hello", "hello2", "hello3"}) + testSerialization(t, []int{12, 12, 12, 4, 4, 4, 3, 5}) + testSerialization(t, myMap) } func testSerialization[V any](t *testing.T, v V) { - var ( - g = gomega.NewWithT(t) - err error - ) - serializer := NewSerializer[V]("json") - g.Expect(serializer).To(gomega.Not(gomega.BeNil())) + if serializer == nil { + t.Fatal("expected serializer to be non-nil") + } value, err := serializer.Serialize(v) - g.Expect(err).ShouldNot(gomega.HaveOccurred()) - finaValue, err := serializer.Deserialize(value) - g.Expect(err).ShouldNot(gomega.HaveOccurred()) - g.Expect(*finaValue).To(gomega.Equal(v)) + if err != nil { + t.Fatalf("Serialize failed for value %#v: %v", v, err) + } + + finalValue, err := serializer.Deserialize(value) + if err != nil { + t.Fatalf("Deserialize failed for value %#v: %v", v, err) + } + + if !reflect.DeepEqual(*finalValue, v) { + t.Fatalf("expected deserialized value %#v to equal original %#v", *finalValue, v) + } } diff --git a/coherence/session_test.go b/coherence/session_test.go index 62b66c31..c34ba2b4 100644 --- a/coherence/session_test.go +++ b/coherence/session_test.go @@ -8,107 +8,131 @@ package coherence import ( "context" - "github.com/onsi/gomega" "strconv" "testing" "time" ) func TestSessionValidation(t *testing.T) { - var ( - g = gomega.NewWithT(t) - err error - ctx = context.Background() - ) + ctx := context.Background() - _, err = NewSession(ctx, WithFormat("not-json")) - g.Expect(err).To(gomega.Equal(ErrInvalidFormat)) + _, err := NewSession(ctx, WithFormat("not-json")) + if err != ErrInvalidFormat { + t.Fatalf("expected ErrInvalidFormat, got %v", err) + } // test default timeout - timeout, _ := strconv.ParseInt(defaultRequestTimeout, 10, 64) + timeout, err := strconv.ParseInt(defaultRequestTimeout, 10, 64) + if err != nil { + t.Fatalf("failed to parse default request timeout: %v", err) + } + s, err := NewSession(ctx) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(s.sessOpts.RequestTimeout).To(gomega.Equal(time.Duration(timeout) * time.Millisecond)) + if err != nil { + t.Fatalf("unexpected error creating default session: %v", err) + } + if got := s.sessOpts.RequestTimeout; got != time.Duration(timeout)*time.Millisecond { + t.Fatalf("expected default timeout %v, got %v", time.Duration(timeout)*time.Millisecond, got) + } // test setting a request timeout - s, err = NewSession(ctx, WithRequestTimeout(time.Duration(33)*time.Millisecond)) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(s.sessOpts.RequestTimeout).To(gomega.Equal(time.Duration(33) * time.Millisecond)) + s, err = NewSession(ctx, WithRequestTimeout(33*time.Millisecond)) + if err != nil { + t.Fatalf("unexpected error setting request timeout: %v", err) + } + if got := s.sessOpts.RequestTimeout; got != 33*time.Millisecond { + t.Fatalf("expected request timeout 33ms, got %v", got) + } // test setting a disconnected timeout - s, err = NewSession(ctx, WithDisconnectTimeout(time.Duration(34)*time.Millisecond)) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(s.sessOpts.DisconnectTimeout).To(gomega.Equal(time.Duration(34) * time.Millisecond)) + s, err = NewSession(ctx, WithDisconnectTimeout(34*time.Millisecond)) + if err != nil { + t.Fatalf("unexpected error setting disconnect timeout: %v", err) + } + if got := s.sessOpts.DisconnectTimeout; got != 34*time.Millisecond { + t.Fatalf("expected disconnect timeout 34ms, got %v", got) + } // test setting a ready timeout - s, err = NewSession(ctx, WithReadyTimeout(time.Duration(35)*time.Millisecond)) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(s.sessOpts.ReadyTimeout).To(gomega.Equal(time.Duration(35) * time.Millisecond)) + s, err = NewSession(ctx, WithReadyTimeout(35*time.Millisecond)) + if err != nil { + t.Fatalf("unexpected error setting ready timeout: %v", err) + } + if got := s.sessOpts.ReadyTimeout; got != 35*time.Millisecond { + t.Fatalf("expected ready timeout 35ms, got %v", got) + } } func TestSessionEnvValidation(t *testing.T) { - var ( - g = gomega.NewWithT(t) - err error - ctx = context.Background() - ) + ctx := context.Background() - // test default timeout t.Setenv("COHERENCE_CLIENT_REQUEST_TIMEOUT", "5000") s, err := NewSession(ctx) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(s.sessOpts.RequestTimeout).To(gomega.Equal(time.Duration(5000) * time.Millisecond)) + if err != nil { + t.Fatalf("unexpected error creating session: %v", err) + } + if got := s.sessOpts.RequestTimeout; got != 5000*time.Millisecond { + t.Fatalf("expected request timeout 5000ms, got %v", got) + } - // test setting a disconnected timeout t.Setenv("COHERENCE_SESSION_DISCONNECT_TIMEOUT", "6000") s, err = NewSession(ctx) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(s.sessOpts.DisconnectTimeout).To(gomega.Equal(time.Duration(6000) * time.Millisecond)) + if err != nil { + t.Fatalf("unexpected error creating session with disconnect timeout: %v", err) + } + if got := s.sessOpts.DisconnectTimeout; got != 6000*time.Millisecond { + t.Fatalf("expected disconnect timeout 6000ms, got %v", got) + } - // test setting a ready timeout t.Setenv("COHERENCE_READY_TIMEOUT", "7000") s, err = NewSession(ctx) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(s.sessOpts.ReadyTimeout).To(gomega.Equal(time.Duration(7000) * time.Millisecond)) + if err != nil { + t.Fatalf("unexpected error creating session with ready timeout: %v", err) + } + if got := s.sessOpts.ReadyTimeout; got != 7000*time.Millisecond { + t.Fatalf("expected ready timeout 7000ms, got %v", got) + } } func TestSessionEnvDebug(t *testing.T) { - var ( - g = gomega.NewWithT(t) - ctx = context.Background() - ) + ctx := context.Background() t.Setenv(envSessionDebug, "true") + _, err := NewSession(ctx) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) + if err != nil { + t.Fatalf("expected no error creating session with debug env, got: %v", err) + } } func TestConnectionOverride(t *testing.T) { - var ( - g = gomega.NewWithT(t) - ctx = context.Background() - ) + ctx := context.Background() t.Setenv(envHostName, "localhost:12345") + s, err := NewSession(ctx) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(s.sessOpts.Address).To(gomega.Equal("localhost:12345")) + if err != nil { + t.Fatalf("expected no error creating session, got: %v", err) + } + + if s.sessOpts.Address != "localhost:12345" { + t.Fatalf("expected address to be 'localhost:12345', got: %s", s.sessOpts.Address) + } } func TestInvalidFormat(t *testing.T) { - var ( - g = gomega.NewWithT(t) - ctx = context.Background() - ) + ctx := context.Background() + _, err := NewSession(ctx, WithFormat("abc")) - g.Expect(err).To(gomega.HaveOccurred()) + if err == nil { + t.Fatal("expected error when using invalid format, got nil") + } } func TestSessionTimeout(t *testing.T) { - var ( - g = gomega.NewWithT(t) - ctx = context.Background() - ) - + ctx := context.Background() t.Setenv(envRequestTimeout, "-1") + _, err := NewSession(ctx) - g.Expect(err).To(gomega.HaveOccurred()) + if err == nil { + t.Fatal("expected error due to invalid request timeout, got nil") + } } diff --git a/go.mod b/go.mod index 21d267d6..1f557ba4 100644 --- a/go.mod +++ b/go.mod @@ -11,16 +11,13 @@ toolchain go1.23.7 require ( github.com/google/uuid v1.6.0 - github.com/onsi/gomega v1.37.0 - golang.org/x/text v0.25.0 - google.golang.org/grpc v1.72.2 + golang.org/x/text v0.26.0 + google.golang.org/grpc v1.73.0 google.golang.org/protobuf v1.36.6 ) require ( - github.com/google/go-cmp v0.7.0 // indirect - golang.org/x/net v0.40.0 // indirect + golang.org/x/net v0.41.0 // indirect golang.org/x/sys v0.33.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 3d8ef88b..e22d2bc4 100644 --- a/go.sum +++ b/go.sum @@ -2,49 +2,35 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= -github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= -github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/onsi/ginkgo/v2 v2.23.3 h1:edHxnszytJ4lD9D5Jjc4tiDkPBZ3siDeJJkUZJJVkp0= -github.com/onsi/ginkgo/v2 v2.23.3/go.mod h1:zXTP6xIp3U8aVuXN8ENK9IXRaTjFnpVB9mGmaSRvxnM= -github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y= -github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= -go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= -go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= -go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= -go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= -go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A= -go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU= -go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk= -go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= -go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= -go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= +go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ= +go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y= +go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M= +go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE= +go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY= +go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg= +go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o= +go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w= +go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs= +go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc= golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= +golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= +golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= -golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= -golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY= -golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a h1:51aaUVRocpvUOSQKM6Q7VuoaktNIaMCLuhZB6DKksq4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a/go.mod h1:uRxBH1mhmO8PGhU89cMcHaXKZqO+OfakD8QQO0oYwlQ= +golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= +golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a h1:v2PbRU4K3llS09c7zodFpNePeamkAwG3mPrAery9VeE= google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= -google.golang.org/grpc v1.72.2 h1:TdbGzwb82ty4OusHWepvFWGLgIbNo1/SUynEN0ssqv8= -google.golang.org/grpc v1.72.2/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM= +google.golang.org/grpc v1.73.0 h1:VIWSmpI2MegBtTuFt5/JWy2oXxtjJ/e89Z70ImfD2ok= +google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7EVBQc= google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/test/e2e/resolver/run_test.go b/test/e2e/resolver/run_test.go index d2ce5f85..858dcb4a 100644 --- a/test/e2e/resolver/run_test.go +++ b/test/e2e/resolver/run_test.go @@ -10,7 +10,6 @@ import ( "context" "github.com/onsi/gomega" "github.com/oracle/coherence-go-client/v2/coherence" - "github.com/oracle/coherence-go-client/v2/test/utils" "testing" ) @@ -39,5 +38,20 @@ func TestConnectingUsingNSResolver(t *testing.T) { g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) defer session.Close() - utils.RunNSTestWithNamedMap(ctx, g, session, "grpc-ns-test") + RunNSTestWithNamedMap(ctx, g, session, "grpc-ns-test") +} + +func RunNSTestWithNamedMap(ctx context.Context, g *gomega.WithT, session *coherence.Session, cache string) { + namedMap, err := coherence.GetNamedMap[string, string](session, cache) + g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) + defer func() { + _ = namedMap.Destroy(ctx) + }() + + _, err = namedMap.Put(ctx, "one", "ONE") + g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) + + size, err := namedMap.Size(ctx) + g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) + g.Expect(size).To(gomega.Equal(1)) } diff --git a/test/e2e/resolver_cluster/run_test.go b/test/e2e/resolver_cluster/run_test.go index 5eb130c8..52d31457 100644 --- a/test/e2e/resolver_cluster/run_test.go +++ b/test/e2e/resolver_cluster/run_test.go @@ -10,7 +10,6 @@ import ( "context" "github.com/onsi/gomega" "github.com/oracle/coherence-go-client/v2/coherence" - "github.com/oracle/coherence-go-client/v2/test/utils" "testing" ) @@ -50,5 +49,20 @@ func TestConnectingUsingNSResolverMultipleClusters(t *testing.T) { g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) defer session.Close() - utils.RunNSTestWithNamedMap(ctx, g, session, "grpc-ns-test-cluster") + RunNSTestWithNamedMap(ctx, g, session, "grpc-ns-test-cluster") +} + +func RunNSTestWithNamedMap(ctx context.Context, g *gomega.WithT, session *coherence.Session, cache string) { + namedMap, err := coherence.GetNamedMap[string, string](session, cache) + g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) + defer func() { + _ = namedMap.Destroy(ctx) + }() + + _, err = namedMap.Put(ctx, "one", "ONE") + g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) + + size, err := namedMap.Size(ctx) + g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) + g.Expect(size).To(gomega.Equal(1)) } diff --git a/test/e2e/scope/named_map_test.go b/test/e2e/scope/named_map_test.go index c95694ac..41278bd8 100644 --- a/test/e2e/scope/named_map_test.go +++ b/test/e2e/scope/named_map_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -7,12 +7,15 @@ package scope import ( + "context" "github.com/onsi/gomega" "github.com/oracle/coherence-go-client/v2/coherence" "github.com/oracle/coherence-go-client/v2/test/utils" "testing" ) +var localCtx = context.Background() + func TestBasicCrudOperationsVariousTypes(t *testing.T) { var ( g = gomega.NewWithT(t) @@ -24,44 +27,44 @@ func TestBasicCrudOperationsVariousTypes(t *testing.T) { g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() - utils.RunKeyValueTest[int, bool](g, getNewNamedMap[int, bool](g, session, "c10"), 1, false) - utils.RunKeyValueTest[int, bool](g, getNewNamedMap[int, bool](g, session, "c11"), 1, true) - utils.RunKeyValueTest[int, byte](g, getNewNamedMap[int, byte](g, session, "c12"), 1, byte(22)) - utils.RunKeyValueTest[int, string](g, getNewNamedMap[int, string](g, session, "c1"), 1, "Tim") - utils.RunKeyValueTest[int, utils.Person](g, getNewNamedMap[int, utils.Person](g, session, "c2"), 1, utils.Person{ID: 1, Name: "Tim"}) - utils.RunKeyValueTest[int, float32](g, getNewNamedMap[int, float32](g, session, "c3"), 1, float32(1.123)) - utils.RunKeyValueTest[int, float64](g, getNewNamedMap[int, float64](g, session, "c4"), 1, 1.123) - utils.RunKeyValueTest[int, int](g, getNewNamedMap[int, int](g, session, "c5"), 1, 1) - utils.RunKeyValueTest[int, int16](g, getNewNamedMap[int, int16](g, session, "c7"), 1, 10) - utils.RunKeyValueTest[int, int32](g, getNewNamedMap[int, int32](g, session, "c8"), 1, 1333) - utils.RunKeyValueTest[int, int64](g, getNewNamedMap[int, int64](g, session, "c9"), 1, 1333) - utils.RunKeyValueTest[string, utils.Person](g, getNewNamedMap[string, utils.Person](g, session, "c13"), "k1", utils.Person{ID: 1, Name: "Tim"}) - utils.RunKeyValueTest[string, string](g, getNewNamedMap[string, string](g, session, "c14"), "k1", "value1") - utils.RunKeyValueTest[int, utils.Person](g, getNewNamedMap[int, utils.Person](g, session, "c15"), 1, + RunKeyValueTest[int, bool](g, getNewNamedMap[int, bool](g, session, "c10"), 1, false) + RunKeyValueTest[int, bool](g, getNewNamedMap[int, bool](g, session, "c11"), 1, true) + RunKeyValueTest[int, byte](g, getNewNamedMap[int, byte](g, session, "c12"), 1, byte(22)) + RunKeyValueTest[int, string](g, getNewNamedMap[int, string](g, session, "c1"), 1, "Tim") + RunKeyValueTest[int, utils.Person](g, getNewNamedMap[int, utils.Person](g, session, "c2"), 1, utils.Person{ID: 1, Name: "Tim"}) + RunKeyValueTest[int, float32](g, getNewNamedMap[int, float32](g, session, "c3"), 1, float32(1.123)) + RunKeyValueTest[int, float64](g, getNewNamedMap[int, float64](g, session, "c4"), 1, 1.123) + RunKeyValueTest[int, int](g, getNewNamedMap[int, int](g, session, "c5"), 1, 1) + RunKeyValueTest[int, int16](g, getNewNamedMap[int, int16](g, session, "c7"), 1, 10) + RunKeyValueTest[int, int32](g, getNewNamedMap[int, int32](g, session, "c8"), 1, 1333) + RunKeyValueTest[int, int64](g, getNewNamedMap[int, int64](g, session, "c9"), 1, 1333) + RunKeyValueTest[string, utils.Person](g, getNewNamedMap[string, utils.Person](g, session, "c13"), "k1", utils.Person{ID: 1, Name: "Tim"}) + RunKeyValueTest[string, string](g, getNewNamedMap[string, string](g, session, "c14"), "k1", "value1") + RunKeyValueTest[int, utils.Person](g, getNewNamedMap[int, utils.Person](g, session, "c15"), 1, utils.Person{ID: 1, Name: "Tim", HomeAddress: utils.Address{Address1: "a1", Address2: "a2", City: "Perth", State: "WA", PostCode: 6000}}) - utils.RunKeyValueTest[int, []string](g, getNewNamedMap[int, []string](g, session, "c16"), 1, + RunKeyValueTest[int, []string](g, getNewNamedMap[int, []string](g, session, "c16"), 1, []string{"a", "b", "c"}) - utils.RunKeyValueTest[int, map[int]string](g, getNewNamedMap[int, map[int]string](g, session, "c17"), 1, + RunKeyValueTest[int, map[int]string](g, getNewNamedMap[int, map[int]string](g, session, "c17"), 1, map[int]string{1: "one", 2: "two", 3: "three"}) - utils.RunKeyValueTest[int, float64](g, getNewNamedCache[int, float64](g, session, "c4"), 1, 1.123) - utils.RunKeyValueTest[int, int](g, getNewNamedCache[int, int](g, session, "c5"), 1, 1) - utils.RunKeyValueTest[int, int16](g, getNewNamedCache[int, int16](g, session, "c7"), 1, 10) - utils.RunKeyValueTest[int, int32](g, getNewNamedCache[int, int32](g, session, "c8"), 1, 1333) - utils.RunKeyValueTest[int, string](g, getNewNamedCache[int, string](g, session, "c1"), 1, "Tim") - utils.RunKeyValueTest[int, utils.Person](g, getNewNamedCache[int, utils.Person](g, session, "c2"), 1, utils.Person{ID: 1, Name: "Tim"}) - utils.RunKeyValueTest[int, float32](g, getNewNamedCache[int, float32](g, session, "c3"), 1, float32(1.123)) - utils.RunKeyValueTest[int, int64](g, getNewNamedCache[int, int64](g, session, "c9"), 1, 1333) - utils.RunKeyValueTest[int, bool](g, getNewNamedCache[int, bool](g, session, "c10"), 1, false) - utils.RunKeyValueTest[int, bool](g, getNewNamedCache[int, bool](g, session, "c11"), 1, true) - utils.RunKeyValueTest[int, byte](g, getNewNamedCache[int, byte](g, session, "c12"), 1, byte(22)) - utils.RunKeyValueTest[string, utils.Person](g, getNewNamedCache[string, utils.Person](g, session, "c13"), "k1", utils.Person{ID: 1, Name: "Tim"}) - utils.RunKeyValueTest[int, []string](g, getNewNamedCache[int, []string](g, session, "c16"), 1, + RunKeyValueTest[int, float64](g, getNewNamedCache[int, float64](g, session, "c4"), 1, 1.123) + RunKeyValueTest[int, int](g, getNewNamedCache[int, int](g, session, "c5"), 1, 1) + RunKeyValueTest[int, int16](g, getNewNamedCache[int, int16](g, session, "c7"), 1, 10) + RunKeyValueTest[int, int32](g, getNewNamedCache[int, int32](g, session, "c8"), 1, 1333) + RunKeyValueTest[int, string](g, getNewNamedCache[int, string](g, session, "c1"), 1, "Tim") + RunKeyValueTest[int, utils.Person](g, getNewNamedCache[int, utils.Person](g, session, "c2"), 1, utils.Person{ID: 1, Name: "Tim"}) + RunKeyValueTest[int, float32](g, getNewNamedCache[int, float32](g, session, "c3"), 1, float32(1.123)) + RunKeyValueTest[int, int64](g, getNewNamedCache[int, int64](g, session, "c9"), 1, 1333) + RunKeyValueTest[int, bool](g, getNewNamedCache[int, bool](g, session, "c10"), 1, false) + RunKeyValueTest[int, bool](g, getNewNamedCache[int, bool](g, session, "c11"), 1, true) + RunKeyValueTest[int, byte](g, getNewNamedCache[int, byte](g, session, "c12"), 1, byte(22)) + RunKeyValueTest[string, utils.Person](g, getNewNamedCache[string, utils.Person](g, session, "c13"), "k1", utils.Person{ID: 1, Name: "Tim"}) + RunKeyValueTest[int, []string](g, getNewNamedCache[int, []string](g, session, "c16"), 1, []string{"a", "b", "c"}) - utils.RunKeyValueTest[int, map[int]string](g, getNewNamedCache[int, map[int]string](g, session, "c17"), 1, + RunKeyValueTest[int, map[int]string](g, getNewNamedCache[int, map[int]string](g, session, "c17"), 1, map[int]string{1: "one", 2: "two", 3: "three"}) - utils.RunKeyValueTest[string, string](g, getNewNamedCache[string, string](g, session, "c14"), "k1", "value1") - utils.RunKeyValueTest[int, utils.Person](g, getNewNamedCache[int, utils.Person](g, session, "c15"), 1, + RunKeyValueTest[string, string](g, getNewNamedCache[string, string](g, session, "c14"), "k1", "value1") + RunKeyValueTest[int, utils.Person](g, getNewNamedCache[int, utils.Person](g, session, "c15"), 1, utils.Person{ID: 1, Name: "Tim", HomeAddress: utils.Address{Address1: "a1", Address2: "a2", City: "Perth", State: "WA", PostCode: 6000}}) } @@ -78,3 +81,25 @@ func getNewNamedMap[K comparable, V any](g *gomega.WithT, session *coherence.Ses g.Expect(err).ShouldNot(gomega.HaveOccurred()) return namedMap } + +// RunKeyValueTest runs a basic Put/Get test against various key/ values +func RunKeyValueTest[K comparable, V any](g *gomega.WithT, cache coherence.NamedMap[K, V], key K, value V) { + var ( + result *V + err = cache.Clear(localCtx) + oldValue *V + ) + g.Expect(err).NotTo(gomega.HaveOccurred()) + + _, err = cache.Put(localCtx, key, value) + g.Expect(err).NotTo(gomega.HaveOccurred()) + + result, err = cache.Get(localCtx, key) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + + g.Expect(*result).To(gomega.Equal(value)) + + oldValue, err = cache.Remove(localCtx, key) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(oldValue).To(gomega.Equal(result)) +} diff --git a/test/e2e/standalone/aggregator_test.go b/test/e2e/standalone/aggregator_test.go index d0ffb0f0..11e8e3f3 100644 --- a/test/e2e/standalone/aggregator_test.go +++ b/test/e2e/standalone/aggregator_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024 Oracle and/or its affiliates. + * Copyright (c) 2023, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -31,28 +31,28 @@ func TestAggregatorAgainstMapAndCache(t *testing.T) { nameMap coherence.NamedMap[int, utils.Person] test func(t *testing.T, namedCache coherence.NamedMap[int, utils.Person]) }{ - {"NamedMapRunTestCount", utils.GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestCountAggregator}, - {"NamedCacheRunTestCount", utils.GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestCountAggregator}, - {"NamedMapRunTestMin", utils.GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestMinAggregator}, - {"NamedCacheRunTestMin", utils.GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestMinAggregator}, - {"NamedMapRunTestMax", utils.GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestMaxAggregator}, - {"NamedCacheRunTestMax", utils.GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestMaxAggregator}, - {"NamedMapRunTestDistinct", utils.GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestDistinctAggregator}, - {"NamedCacheRunTestDistinct", utils.GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestDistinctAggregator}, - {"NamedMapRunTestGroupBy", utils.GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestGroupByAggregator}, - {"NamedCacheRunTestGroupBy", utils.GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestGroupByAggregator}, - {"NamedMapRunTestTopNAggregator", utils.GetNamedMap[int, utils.Person](g, session, "topn-map"), RunTestTopNAggregator}, - {"NamedCacheRunTestTopNAggregator", utils.GetNamedCache[int, utils.Person](g, session, "topn-cache"), RunTestTopNAggregator}, - {"NamedMapRunTestReducerAggregator", utils.GetNamedMap[int, utils.Person](g, session, "reducer-map"), RunTestReducerAggregator}, - {"NamedCacheRunTestReducerAggregator", utils.GetNamedCache[int, utils.Person](g, session, "reducer-cache"), RunTestReducerAggregator}, - {"NamedMapRunTestQueryRecorderAggregator", utils.GetNamedMap[int, utils.Person](g, session, "query-map"), RunTestQueryRecorderAggregator}, - {"NamedCacheRunTestQueryRecorderAggregator", utils.GetNamedCache[int, utils.Person](g, session, "query-cache"), RunTestQueryRecorderAggregator}, - {"NamedMapRunTestSum", utils.GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestSumAggregator}, - {"NamedCacheRunTestSum", utils.GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestSumAggregator}, - {"NamedMapRunTestAverage", utils.GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestAverageAggregator}, - {"NamedCacheRunTestAverage", utils.GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestAverageAggregator}, - {"NamedMapRunTestPriorityAggregator", utils.GetNamedMap[int, utils.Person](g, session, "priority-map"), RunTestPriorityAggregator}, - {"NamedCacheRunTestPriorityAggregator", utils.GetNamedCache[int, utils.Person](g, session, "priority-cache"), RunTestPriorityAggregator}, + {"NamedMapRunTestCount", GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestCountAggregator}, + {"NamedCacheRunTestCount", GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestCountAggregator}, + {"NamedMapRunTestMin", GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestMinAggregator}, + {"NamedCacheRunTestMin", GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestMinAggregator}, + {"NamedMapRunTestMax", GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestMaxAggregator}, + {"NamedCacheRunTestMax", GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestMaxAggregator}, + {"NamedMapRunTestDistinct", GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestDistinctAggregator}, + {"NamedCacheRunTestDistinct", GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestDistinctAggregator}, + {"NamedMapRunTestGroupBy", GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestGroupByAggregator}, + {"NamedCacheRunTestGroupBy", GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestGroupByAggregator}, + {"NamedMapRunTestTopNAggregator", GetNamedMap[int, utils.Person](g, session, "topn-map"), RunTestTopNAggregator}, + {"NamedCacheRunTestTopNAggregator", GetNamedCache[int, utils.Person](g, session, "topn-cache"), RunTestTopNAggregator}, + {"NamedMapRunTestReducerAggregator", GetNamedMap[int, utils.Person](g, session, "reducer-map"), RunTestReducerAggregator}, + {"NamedCacheRunTestReducerAggregator", GetNamedCache[int, utils.Person](g, session, "reducer-cache"), RunTestReducerAggregator}, + {"NamedMapRunTestQueryRecorderAggregator", GetNamedMap[int, utils.Person](g, session, "query-map"), RunTestQueryRecorderAggregator}, + {"NamedCacheRunTestQueryRecorderAggregator", GetNamedCache[int, utils.Person](g, session, "query-cache"), RunTestQueryRecorderAggregator}, + {"NamedMapRunTestSum", GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestSumAggregator}, + {"NamedCacheRunTestSum", GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestSumAggregator}, + {"NamedMapRunTestAverage", GetNamedMap[int, utils.Person](g, session, "aggregate-map"), RunTestAverageAggregator}, + {"NamedCacheRunTestAverage", GetNamedCache[int, utils.Person](g, session, "aggregate-cache"), RunTestAverageAggregator}, + {"NamedMapRunTestPriorityAggregator", GetNamedMap[int, utils.Person](g, session, "priority-map"), RunTestPriorityAggregator}, + {"NamedCacheRunTestPriorityAggregator", GetNamedCache[int, utils.Person](g, session, "priority-cache"), RunTestPriorityAggregator}, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { diff --git a/test/e2e/standalone/event_test.go b/test/e2e/standalone/event_test.go index 41cfd5c0..20e0cc66 100644 --- a/test/e2e/standalone/event_test.go +++ b/test/e2e/standalone/event_test.go @@ -74,8 +74,8 @@ func TestMapAndLifecycleEventsAll(t *testing.T) { g, session := initTest(t) defer session.Close() - namedCache := utils.GetNamedCache[string, string](g, session, "test-events-all-cache") - namedMap := utils.GetNamedMap[string, string](g, session, "test-events-all-map") + namedCache := GetNamedCache[string, string](g, session, "test-events-all-cache") + namedMap := GetNamedMap[string, string](g, session, "test-events-all-map") runBasicTests(g, namedCache, namedCache.Name(), &expected, -1) runBasicTests(g, namedMap, namedMap.Name(), &expected, -1) @@ -85,8 +85,8 @@ func TestMapAndLifecycleEventsAll1(t *testing.T) { g, session := initTest(t) defer session.Close() - namedCache := utils.GetNamedCache[string, string](g, session, "test-lifecycle-release-cache") - namedMap := utils.GetNamedMap[string, string](g, session, "test-lifecycle-release-map") + namedCache := GetNamedCache[string, string](g, session, "test-lifecycle-release-cache") + namedMap := GetNamedMap[string, string](g, session, "test-lifecycle-release-map") runReleasedLifecycleTests(g, namedMap) runReleasedLifecycleTests(g, namedCache) @@ -96,8 +96,8 @@ func TestMapAndLifecycleEventsAll2(t *testing.T) { g, session := initTest(t) defer session.Close() - namedCache := utils.GetNamedCache[string, string](g, session, "test-lifecycle-all-cache-multi") - namedMap := utils.GetNamedMap[string, string](g, session, "test-lifecycle-all-map-multi") + namedCache := GetNamedCache[string, string](g, session, "test-lifecycle-all-cache-multi") + namedMap := GetNamedMap[string, string](g, session, "test-lifecycle-all-map-multi") runMultipleLifecycleTests(g, namedMap) runMultipleLifecycleTests(g, namedCache) @@ -107,8 +107,8 @@ func TestMapAndLifecycleEventsAll3(t *testing.T) { g, session := initTest(t) defer session.Close() - namedCache := utils.GetNamedCache[string, string](g, session, "test-lifecycle-all-cache") - namedMap := utils.GetNamedMap[string, string](g, session, "test-lifecycle-all-map") + namedCache := GetNamedCache[string, string](g, session, "test-lifecycle-all-cache") + namedMap := GetNamedMap[string, string](g, session, "test-lifecycle-all-map") runBasicLifecycleTests(g, namedMap, namedMap.Name()) runBasicLifecycleTests(g, namedCache, namedCache.Name()) @@ -123,8 +123,8 @@ func TestMapAndLifecycleEventsAll4(t *testing.T) { t.Skip("Skip for gRPC v0") } - namedCache := utils.GetNamedCache[string, string](g, session, "test-lifecycle-all-cache") - namedMap := utils.GetNamedMap[string, string](g, session, "test-lifecycle-all-map") + namedCache := GetNamedCache[string, string](g, session, "test-lifecycle-all-cache") + namedMap := GetNamedMap[string, string](g, session, "test-lifecycle-all-map") runMultipleLifecycleTests(g, namedMap) runMultipleLifecycleTests(g, namedCache) @@ -134,7 +134,7 @@ func TestExpiringEvents(t *testing.T) { g, session := initTest(t) defer session.Close() - runTestExpiringEvents(g, utils.GetNamedCache[string, string](g, session, "test-expiring-events-cache")) + runTestExpiringEvents(g, GetNamedCache[string, string](g, session, "test-expiring-events-cache")) } // TestEventDisconnect tests to ensure that if we get a disconnect, then we can rec-connect and @@ -149,12 +149,12 @@ func TestEventDisconnect(t *testing.T) { t.Skip("Skip for gRPC v0") } - namedCache := utils.GetNamedCache[string, string](g, session, "test-reconnect-cache") + namedCache := GetNamedCache[string, string](g, session, "test-reconnect-cache") g.Expect(namedCache.Clear(ctx)).To(gomega.BeNil()) RunTestReconnect(g, namedCache, true) - namedMap := utils.GetNamedMap[string, string](g, session, "test-reconnect-map") + namedMap := GetNamedMap[string, string](g, session, "test-reconnect-map") g.Expect(namedMap.Clear(ctx)).To(gomega.BeNil()) RunTestReconnect(g, namedMap, true) } @@ -177,10 +177,10 @@ func TestEventDisconnectWithReadyTimeoutDelay(t *testing.T) { t.Skip("Skip for gRPC v0") } - namedCache := utils.GetNamedCache[string, string](g, session, "test-reconnect-cache") + namedCache := GetNamedCache[string, string](g, session, "test-reconnect-cache") RunTestReconnect(g, namedCache, false) - namedMap := utils.GetNamedMap[string, string](g, session, "test-reconnect-map") + namedMap := GetNamedMap[string, string](g, session, "test-reconnect-map") RunTestReconnect(g, namedMap, false) } @@ -203,8 +203,8 @@ func TestMapEventInsertsOnly(t *testing.T) { g, session := initTest(t) defer session.Close() - namedCache := utils.GetNamedCache[string, string](g, session, "test-events-inserts-only-cache") - namedMap := utils.GetNamedMap[string, string](g, session, "test-events-inserts-only-map") + namedCache := GetNamedCache[string, string](g, session, "test-events-inserts-only-cache") + namedMap := GetNamedMap[string, string](g, session, "test-events-inserts-only-map") runBasicTests(g, namedCache, namedCache.Name(), &expected, filters.MaskInserted) runBasicTests(g, namedMap, namedMap.Name(), &expected, filters.MaskInserted) @@ -230,8 +230,8 @@ func TestMapEventUpdatesOnly(t *testing.T) { g, session := initTest(t) defer session.Close() - namedCache := utils.GetNamedCache[string, string](g, session, "test-events-updates-only-cache") - namedMap := utils.GetNamedMap[string, string](g, session, "test-events-updates-only-map") + namedCache := GetNamedCache[string, string](g, session, "test-events-updates-only-cache") + namedMap := GetNamedMap[string, string](g, session, "test-events-updates-only-map") runBasicTests(g, namedCache, namedCache.Name(), &expected, filters.MaskUpdated) runBasicTests(g, namedMap, namedMap.Name(), &expected, filters.MaskUpdated) @@ -257,8 +257,8 @@ func TestMapEventDeletesOnly(t *testing.T) { g, session := initTest(t) defer session.Close() - namedCache := utils.GetNamedCache[string, string](g, session, "test-events-deletes-only-cache") - namedMap := utils.GetNamedMap[string, string](g, session, "test-events-deletes-only-map") + namedCache := GetNamedCache[string, string](g, session, "test-events-deletes-only-cache") + namedMap := GetNamedMap[string, string](g, session, "test-events-deletes-only-map") runBasicTests(g, namedCache, namedCache.Name(), &expected, filters.MaskDeleted) runBasicTests(g, namedMap, namedMap.Name(), &expected, filters.MaskDeleted) @@ -271,8 +271,8 @@ func TestMapEventMultipleListeners(t *testing.T) { defer session.Close() testMaps := []coherence.NamedMap[string, string]{ - utils.GetNamedCache[string, string](g, session, "event-multiple-listeners-cache"), - utils.GetNamedMap[string, string](g, session, "event-multiple-listeners-map"), + GetNamedCache[string, string](g, session, "event-multiple-listeners-cache"), + GetNamedMap[string, string](g, session, "event-multiple-listeners-map"), } // run tests against NamedMap and NamedCache @@ -471,7 +471,7 @@ func TestCustomFilterListener(t *testing.T) { g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() - cache := utils.GetNamedCache[string, utils.Person](g, session, "event-filter-listener") + cache := GetNamedCache[string, utils.Person](g, session, "event-filter-listener") defer func(cache coherence.NamedCache[string, utils.Person], ctx context.Context) { err := cache.Destroy(ctx) if err != nil { @@ -528,7 +528,7 @@ func TestKeyListener(t *testing.T) { g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() - cache := utils.GetNamedCache[string, utils.Person](g, session, "event-key-listener") + cache := GetNamedCache[string, utils.Person](g, session, "event-key-listener") defer func(cache coherence.NamedCache[string, utils.Person], ctx context.Context) { err := cache.Destroy(ctx) if err != nil { @@ -584,7 +584,7 @@ func TestLiteListeners(t *testing.T) { g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() - cache := utils.GetNamedCache[string, utils.Person](g, session, "event-lite-listener") + cache := GetNamedCache[string, utils.Person](g, session, "event-lite-listener") defer func(cache coherence.NamedCache[string, utils.Person], ctx context.Context) { err := cache.Destroy(ctx) if err != nil { diff --git a/test/e2e/standalone/filter_test.go b/test/e2e/standalone/filter_test.go index 55352d50..f306de1f 100644 --- a/test/e2e/standalone/filter_test.go +++ b/test/e2e/standalone/filter_test.go @@ -93,108 +93,108 @@ func TestFiltersAgainstMapAndCache(t *testing.T) { filter filters.Filter shouldRemove bool }{ - {"NamedMapBetweenFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageBetween1and9, false}, - {"NamedMapBetweenFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageBetween9and11, true}, - {"NamedCacheBetweenFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageBetween1and9, false}, - {"NamedCacheBetweenFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageBetween9and11, true}, - {"NamedMapEqualFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageEquals9, false}, - {"NamedMapEqualFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageEquals10, true}, - {"NamedCacheEqualFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageEquals9, false}, - {"NamedCacheEqualFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageEquals10, true}, - {"NamedMapInFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageInFalse, false}, - {"NamedMapInFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageInTrue, true}, - {"NamedCacheInFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageInFalse, false}, - {"NamedCacheInFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageInTrue, true}, - {"NamedMapInFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameInFalse, false}, - {"NamedMapInFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageInTrue, true}, - {"NamedCacheInFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameInFalse, false}, - {"NamedCacheInFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameInTrue, true}, - {"NamedMapGreaterFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterThan11, false}, - {"NamedMapGreaterFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameInTrue, true}, - {"NamedCacheGreaterFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterThan11, false}, - {"NamedCacheGreaterFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterThan9, true}, - {"NamedMapGreaterEqualFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterEqual11, false}, - {"NamedMapGreaterEqualFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterEqual10, true}, - {"NamedCacheGreaterEqualFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterEqual11, false}, - {"NamedCacheGreaterEqualFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterEqual10, true}, - {"NamedMapLessFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageLess3, false}, - {"NamedMapLessFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageLess11, true}, - {"NamedCacheLessFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageLess3, false}, - {"NamedCacheLessFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageLess11, true}, - {"NamedMapLessEqualFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageLessEqual3, false}, - {"NamedMapLessEqualFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageLessEqual10, true}, - {"NamedCacheLessEqualFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageLessEqual3, false}, - {"NamedCacheLessEqualFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageLessEqual10, true}, - {"NamedMapInMelbourneFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, livesInMelbourne, false}, - {"NamedMapPerthFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, livesInPerth, true}, - {"NamedCacheMelbourneFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, livesInMelbourne, false}, - {"NamedCachePerthFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, livesInPerth, true}, - {"NamedMapLikeFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeJo, false}, - {"NamedMapLikeFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeTi, true}, - {"NamedCacheLikeFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeJo, false}, - {"NamedCacheLikeFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeTi, true}, - {"NamedMapLikeIgnoreFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeJoIgnore, false}, - {"NamedMapLikeIgnoreFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeTiIgnore, true}, - {"NamedCacheLikeIgnoreFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeJoIgnore, false}, - {"NamedCacheLikeIgnoreFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeTiIgnore, true}, - {"NamedMapLikeIgnoreChainedFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, cityLikeMel, false}, - {"NamedMapLikeIgnoreChainedFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, cityLikePer, true}, - {"NamedCacheLikeIgnoreChainedFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, cityLikeMel, false}, - {"NamedCacheLikeIgnoreChained Filter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, cityLikePer, true}, - {"NamedMapNotFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameNotTim, false}, - {"NamedMapNotFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameNotJohn, true}, - {"NamedCacheNotFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameNotTim, false}, - {"NamedCacheNotFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameNotJohn, true}, - {"NamedMapNotEqualFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageNot10, false}, - {"NamedMapNotEqualFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageNot11, true}, - {"NamedCacheNotEqualFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageNot10, false}, - {"NamedCacheNotEqualFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageNot11, true}, - {"NamedMapOrFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs11OrNameJohn, false}, - {"NamedMapOrFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs11OrNameTim, true}, - {"NamedCacheOrFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs11OrNameJohn, false}, - {"NamedCacheOrFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs11OrNameTim, true}, - {"NamedMapAndFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs10andNameJohn, false}, - {"NamedMapAndFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs10andNameTim, true}, - {"NamedCacheAndFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs10andNameJohn, false}, - {"NamedCacheAndFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs10andNameTim, true}, - {"NamedMapXorFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, xorFalse, false}, - {"NamedMapXorFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, xorTrue, true}, - {"NamedCacheXorFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, xorFalse, false}, - {"NamedCacheXorFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, xorTrue, true}, - {"NamedMapXor2Filter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, xor2False, false}, - {"NamedMapXor2Filter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, xor2True, true}, - {"NamedCacheXor2Filter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, xor2False, false}, - {"NamedCacheXor2Filter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, xor2True, true}, - {"NamedMapAnyFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, anyFalse, false}, - {"NamedMapAnyFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, anyTrue, true}, - {"NamedCacheAnyFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, anyFalse, false}, - {"NamedCacheAnyFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, anyTrue, true}, - {"NamedMapAllFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, allFalse, false}, - {"NamedMapAllFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, allTrue, true}, - {"NamedCacheAllFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, allFalse, false}, - {"NamedCacheAllFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, allTrue, true}, - {"NamedMapContainsAnyFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsAnyFalse, false}, - {"NamedMapContainsAnyFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsAnyTrue, true}, - {"NamedCacheContainsAnyFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, containsAnyFalse, false}, - {"NamedCacheContainsAnyFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, containsAnyTrue, true}, - {"NamedMapContainsAllFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsAllFalse, false}, - {"NamedMapContainsAllFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsAllTrue, true}, - {"NamedMapContainsFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsFalse, false}, - {"NamedMapContainsFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsTrue, true}, - {"NamedCacheContainsAllFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, containsAllFalse, false}, - {"NamedCacheContainsAllFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, containsAllTrue, true}, - {"NamedMapRegExpFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, regExpFalse, false}, - {"NamedMapRegExpFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, regExpTrue, true}, - {"NamedCacheRegExpFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, regExpFalse, false}, - {"NamedCacheRegExpFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, regExpTrue, true}, - {"NamedMapIsNilFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, isNilFalse, false}, - {"NamedMapIsNilFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, isNilTrue, true}, - {"NamedCacheIsNilFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, isNilFalse, false}, - {"NamedCacheIsNilFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, isNilTrue, true}, - {"NamedMapIsNotNilFilter1", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, isNotNilFalse, false}, - {"NamedMapIsNotNilFilter2", utils.GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, isNotNilTrue, true}, - {"NamedCacheIsNotNilFilter1", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, isNotNilFalse, false}, - {"NamedCacheIsNotNilFilter2", utils.GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, isNotNilTrue, true}, + {"NamedMapBetweenFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageBetween1and9, false}, + {"NamedMapBetweenFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageBetween9and11, true}, + {"NamedCacheBetweenFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageBetween1and9, false}, + {"NamedCacheBetweenFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageBetween9and11, true}, + {"NamedMapEqualFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageEquals9, false}, + {"NamedMapEqualFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageEquals10, true}, + {"NamedCacheEqualFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageEquals9, false}, + {"NamedCacheEqualFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageEquals10, true}, + {"NamedMapInFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageInFalse, false}, + {"NamedMapInFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageInTrue, true}, + {"NamedCacheInFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageInFalse, false}, + {"NamedCacheInFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageInTrue, true}, + {"NamedMapInFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameInFalse, false}, + {"NamedMapInFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageInTrue, true}, + {"NamedCacheInFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameInFalse, false}, + {"NamedCacheInFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameInTrue, true}, + {"NamedMapGreaterFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterThan11, false}, + {"NamedMapGreaterFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameInTrue, true}, + {"NamedCacheGreaterFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterThan11, false}, + {"NamedCacheGreaterFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterThan9, true}, + {"NamedMapGreaterEqualFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterEqual11, false}, + {"NamedMapGreaterEqualFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterEqual10, true}, + {"NamedCacheGreaterEqualFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterEqual11, false}, + {"NamedCacheGreaterEqualFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageGreaterEqual10, true}, + {"NamedMapLessFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageLess3, false}, + {"NamedMapLessFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageLess11, true}, + {"NamedCacheLessFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageLess3, false}, + {"NamedCacheLessFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageLess11, true}, + {"NamedMapLessEqualFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageLessEqual3, false}, + {"NamedMapLessEqualFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageLessEqual10, true}, + {"NamedCacheLessEqualFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageLessEqual3, false}, + {"NamedCacheLessEqualFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageLessEqual10, true}, + {"NamedMapInMelbourneFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, livesInMelbourne, false}, + {"NamedMapPerthFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, livesInPerth, true}, + {"NamedCacheMelbourneFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, livesInMelbourne, false}, + {"NamedCachePerthFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, livesInPerth, true}, + {"NamedMapLikeFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeJo, false}, + {"NamedMapLikeFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeTi, true}, + {"NamedCacheLikeFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeJo, false}, + {"NamedCacheLikeFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeTi, true}, + {"NamedMapLikeIgnoreFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeJoIgnore, false}, + {"NamedMapLikeIgnoreFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeTiIgnore, true}, + {"NamedCacheLikeIgnoreFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeJoIgnore, false}, + {"NamedCacheLikeIgnoreFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameLikeTiIgnore, true}, + {"NamedMapLikeIgnoreChainedFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, cityLikeMel, false}, + {"NamedMapLikeIgnoreChainedFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, cityLikePer, true}, + {"NamedCacheLikeIgnoreChainedFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, cityLikeMel, false}, + {"NamedCacheLikeIgnoreChained Filter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, cityLikePer, true}, + {"NamedMapNotFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameNotTim, false}, + {"NamedMapNotFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, nameNotJohn, true}, + {"NamedCacheNotFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameNotTim, false}, + {"NamedCacheNotFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, nameNotJohn, true}, + {"NamedMapNotEqualFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageNot10, false}, + {"NamedMapNotEqualFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageNot11, true}, + {"NamedCacheNotEqualFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageNot10, false}, + {"NamedCacheNotEqualFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageNot11, true}, + {"NamedMapOrFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs11OrNameJohn, false}, + {"NamedMapOrFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs11OrNameTim, true}, + {"NamedCacheOrFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs11OrNameJohn, false}, + {"NamedCacheOrFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs11OrNameTim, true}, + {"NamedMapAndFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs10andNameJohn, false}, + {"NamedMapAndFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs10andNameTim, true}, + {"NamedCacheAndFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs10andNameJohn, false}, + {"NamedCacheAndFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, ageIs10andNameTim, true}, + {"NamedMapXorFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, xorFalse, false}, + {"NamedMapXorFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, xorTrue, true}, + {"NamedCacheXorFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, xorFalse, false}, + {"NamedCacheXorFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, xorTrue, true}, + {"NamedMapXor2Filter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, xor2False, false}, + {"NamedMapXor2Filter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, xor2True, true}, + {"NamedCacheXor2Filter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, xor2False, false}, + {"NamedCacheXor2Filter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, xor2True, true}, + {"NamedMapAnyFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, anyFalse, false}, + {"NamedMapAnyFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, anyTrue, true}, + {"NamedCacheAnyFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, anyFalse, false}, + {"NamedCacheAnyFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, anyTrue, true}, + {"NamedMapAllFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, allFalse, false}, + {"NamedMapAllFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, allTrue, true}, + {"NamedCacheAllFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, allFalse, false}, + {"NamedCacheAllFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, allTrue, true}, + {"NamedMapContainsAnyFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsAnyFalse, false}, + {"NamedMapContainsAnyFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsAnyTrue, true}, + {"NamedCacheContainsAnyFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, containsAnyFalse, false}, + {"NamedCacheContainsAnyFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, containsAnyTrue, true}, + {"NamedMapContainsAllFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsAllFalse, false}, + {"NamedMapContainsAllFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsAllTrue, true}, + {"NamedMapContainsFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsFalse, false}, + {"NamedMapContainsFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, containsTrue, true}, + {"NamedCacheContainsAllFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, containsAllFalse, false}, + {"NamedCacheContainsAllFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, containsAllTrue, true}, + {"NamedMapRegExpFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, regExpFalse, false}, + {"NamedMapRegExpFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, regExpTrue, true}, + {"NamedCacheRegExpFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, regExpFalse, false}, + {"NamedCacheRegExpFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, regExpTrue, true}, + {"NamedMapIsNilFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, isNilFalse, false}, + {"NamedMapIsNilFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, isNilTrue, true}, + {"NamedCacheIsNilFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, isNilFalse, false}, + {"NamedCacheIsNilFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, isNilTrue, true}, + {"NamedMapIsNotNilFilter1", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, isNotNilFalse, false}, + {"NamedMapIsNotNilFilter2", GetNamedMap[int, utils.Person](g, session, "filter"), RunTestFilter, isNotNilTrue, true}, + {"NamedCacheIsNotNilFilter1", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, isNotNilFalse, false}, + {"NamedCacheIsNotNilFilter2", GetNamedCache[int, utils.Person](g, session, "filter"), RunTestFilter, isNotNilTrue, true}, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { @@ -216,8 +216,8 @@ func TestPresentFilter(t *testing.T) { nameMap coherence.NamedMap[int, utils.Person] test func(t *testing.T, namedCache coherence.NamedMap[int, utils.Person]) }{ - {"NamedMapRunTestPresentFilter", utils.GetNamedMap[int, utils.Person](g, session, "present"), RunTestPresentFilter}, - {"NamedCacheRunTestPresentFilter", utils.GetNamedCache[int, utils.Person](g, session, "present"), RunTestPresentFilter}, + {"NamedMapRunTestPresentFilter", GetNamedMap[int, utils.Person](g, session, "present"), RunTestPresentFilter}, + {"NamedCacheRunTestPresentFilter", GetNamedCache[int, utils.Person](g, session, "present"), RunTestPresentFilter}, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { @@ -238,12 +238,12 @@ func RunTestFilter(t *testing.T, namedMap coherence.NamedMap[int, utils.Person], err = namedMap.Clear(ctx) g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - utils.AssertSize(g, namedMap, 0) + AssertSize(g, namedMap, 0) // add a new Person _, err = namedMap.Put(ctx, 1, person) g.Expect(err).NotTo(gomega.HaveOccurred()) - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) // Attempt to remove the person using the supplied filter current, err = coherence.Invoke[int, utils.Person, utils.Person](ctx, namedMap, 1, processors.ConditionalRemove(filter, true)) @@ -251,13 +251,13 @@ func RunTestFilter(t *testing.T, namedMap coherence.NamedMap[int, utils.Person], if shouldRemove { // The cache size should be zero g.Expect(err).NotTo(gomega.HaveOccurred()) - utils.AssertSize(g, namedMap, 0) + AssertSize(g, namedMap, 0) } else { // should not remove and should return the current value g.Expect(err).ShouldNot(gomega.HaveOccurred()) g.Expect(current).To(gomega.Not(gomega.BeNil())) g.Expect(*current).To(gomega.Equal(person)) - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) } } @@ -271,7 +271,7 @@ func RunTestPresentFilter(t *testing.T, namedMap coherence.NamedMap[int, utils.P err = namedMap.Clear(ctx) g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - utils.AssertSize(g, namedMap, 0) + AssertSize(g, namedMap, 0) // Attempt to remove the person using the PresentFilter, this will not work as the entry is not there oldValue, err = coherence.Invoke[int, utils.Person, utils.Person](ctx, namedMap, 1, processors.ConditionalRemove(filters.Present(), true)) @@ -284,5 +284,5 @@ func RunTestPresentFilter(t *testing.T, namedMap coherence.NamedMap[int, utils.P oldValue, err = coherence.Invoke[int, utils.Person, utils.Person](ctx, namedMap, 1, processors.ConditionalRemove(filters.Present(), true)) g.Expect(err).NotTo(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.BeNil()) - utils.AssertSize(g, namedMap, 0) + AssertSize(g, namedMap, 0) } diff --git a/test/e2e/standalone/index_test.go b/test/e2e/standalone/index_test.go index 27efacd6..45ca35bb 100644 --- a/test/e2e/standalone/index_test.go +++ b/test/e2e/standalone/index_test.go @@ -31,8 +31,8 @@ func TestIndexAgainstMapAndCache(t *testing.T) { nameMap coherence.NamedMap[int, utils.Person] test func(t *testing.T, namedCache coherence.NamedMap[int, utils.Person]) }{ - {"NamedMapRunTestIndex", utils.GetNamedMap[int, utils.Person](g, session, "index-map"), RunTestIndex}, - {"NamedCacheRunTestIndex", utils.GetNamedCache[int, utils.Person](g, session, "index-cache"), RunTestIndex}, + {"NamedMapRunTestIndex", GetNamedMap[int, utils.Person](g, session, "index-map"), RunTestIndex}, + {"NamedCacheRunTestIndex", GetNamedCache[int, utils.Person](g, session, "index-cache"), RunTestIndex}, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { diff --git a/test/e2e/standalone/java_object_test.go b/test/e2e/standalone/java_object_test.go index e747e38a..ba19507f 100644 --- a/test/e2e/standalone/java_object_test.go +++ b/test/e2e/standalone/java_object_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024 Oracle and/or its affiliates. + * Copyright (c) 2023, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -45,8 +45,8 @@ func TestJavaSerializationAgainstMapAndCache(t *testing.T) { nameMap coherence.NamedMap[int, Customer] test func(t *testing.T, namedCache coherence.NamedMap[int, Customer]) }{ - {"NamedMapSerializationTest", utils.GetNamedMap[int, Customer](g, session, "customer-map"), RunSerializationTest}, - {"NamedCacheSerializationTest", utils.GetNamedCache[int, Customer](g, session, "customer-cache"), RunSerializationTest}, + {"NamedMapSerializationTest", GetNamedMap[int, Customer](g, session, "customer-map"), RunSerializationTest}, + {"NamedCacheSerializationTest", GetNamedCache[int, Customer](g, session, "customer-cache"), RunSerializationTest}, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { diff --git a/test/e2e/standalone/lifecycle_test.go b/test/e2e/standalone/lifecycle_test.go index 9fa275c5..a2938c7d 100644 --- a/test/e2e/standalone/lifecycle_test.go +++ b/test/e2e/standalone/lifecycle_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024 Oracle and/or its affiliates. + * Copyright (c) 2023, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -26,10 +26,10 @@ func TestCacheLifecycle(t *testing.T) { nameMap coherence.NamedMap[int, utils.Person] test func(t *testing.T, namedCache coherence.NamedMap[int, utils.Person]) }{ - {"NamedMapRunTestDestroy", utils.GetNamedMap[int, utils.Person](g, session, "destroy-map"), RunTestDestroy}, - {"NamedCacheRunTestDestroy", utils.GetNamedCache[int, utils.Person](g, session, "destroy-cache"), RunTestDestroy}, - {"NamedMapRunTestRelease", utils.GetNamedMap[int, utils.Person](g, session, "release-map"), RunTestRelease}, - {"NamedCacheRunTestRelease", utils.GetNamedCache[int, utils.Person](g, session, "release-cache"), RunTestRelease}, + {"NamedMapRunTestDestroy", GetNamedMap[int, utils.Person](g, session, "destroy-map"), RunTestDestroy}, + {"NamedCacheRunTestDestroy", GetNamedCache[int, utils.Person](g, session, "destroy-cache"), RunTestDestroy}, + {"NamedMapRunTestRelease", GetNamedMap[int, utils.Person](g, session, "release-map"), RunTestRelease}, + {"NamedCacheRunTestRelease", GetNamedCache[int, utils.Person](g, session, "release-cache"), RunTestRelease}, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { diff --git a/test/e2e/standalone/named_cache_test.go b/test/e2e/standalone/named_cache_test.go index b413ca95..c4ce0e42 100644 --- a/test/e2e/standalone/named_cache_test.go +++ b/test/e2e/standalone/named_cache_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -30,19 +30,19 @@ func TestPutWithExpiry(t *testing.T) { g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() g.Expect(err).ShouldNot(gomega.HaveOccurred()) - namedCache := utils.GetNamedCache[int, utils.Person](g, session, "put-with-expiry") + namedCache := GetNamedCache[int, utils.Person](g, session, "put-with-expiry") defer session.Close() oldValue, err = namedCache.PutWithExpiry(ctx, person1.ID, person1, time.Duration(5)*time.Second) g.Expect(err).NotTo(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.BeNil()) - utils.AssertSize[int, utils.Person](g, namedCache, 1) + AssertSize[int, utils.Person](g, namedCache, 1) // sleep for 6 seconds to allow entry to expire time.Sleep(6 * time.Second) - utils.AssertSize[int, utils.Person](g, namedCache, 0) + AssertSize[int, utils.Person](g, namedCache, 0) // check that expiry is not > 2147483647 or Integer.MAX_VALUE in Java _, err = namedCache.PutWithExpiry(ctx, person1.ID, person1, time.Duration(2147483647+1)*time.Millisecond) @@ -61,7 +61,7 @@ func TestPutAllWithExpiry(t *testing.T) { g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() g.Expect(err).ShouldNot(gomega.HaveOccurred()) - namedCache := utils.GetNamedCache[int, utils.Person](g, session, "put-all-with-expiry") + namedCache := GetNamedCache[int, utils.Person](g, session, "put-all-with-expiry") err = namedCache.PutAllWithExpiry(ctx, peopleData, time.Duration(4)*time.Second) if namedCache.GetSession().GetProtocolVersion() == 0 { @@ -114,12 +114,12 @@ func TestPutWithExpiryUsingCacheOption(t *testing.T) { _, err = namedCache.Put(ctx, person1.ID, person1) g.Expect(err).NotTo(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.BeNil()) - utils.AssertSize[int, utils.Person](g, namedCache, 1) + AssertSize[int, utils.Person](g, namedCache, 1) // sleep for 6 seconds to allow entry to expire time.Sleep(6 * time.Second) - utils.AssertSize[int, utils.Person](g, namedCache, 0) + AssertSize[int, utils.Person](g, namedCache, 0) // issue a PutWithExpiry which should override the default expiry _, err = namedCache.PutWithExpiry(ctx, person1.ID, person1, time.Duration(10)*time.Second) @@ -128,11 +128,11 @@ func TestPutWithExpiryUsingCacheOption(t *testing.T) { // sleep for 6 seconds, the entry should still be present time.Sleep(6 * time.Second) - utils.AssertSize[int, utils.Person](g, namedCache, 1) + AssertSize[int, utils.Person](g, namedCache, 1) // sleep for 6 seconds, the entry should now honour the 10-second expiry time.Sleep(6 * time.Second) - utils.AssertSize[int, utils.Person](g, namedCache, 0) + AssertSize[int, utils.Person](g, namedCache, 0) } // TestBooleanAndFilters tests to ensure that boolean values are serialized correctly for filters. @@ -149,7 +149,7 @@ func TestBooleanAndFilters(t *testing.T) { session, err := utils.GetSession() g.Expect(err).ShouldNot(gomega.HaveOccurred()) - namedCache := utils.GetNamedCache[int, utils.BooleanTest](g, session, "bool-test") + namedCache := GetNamedCache[int, utils.BooleanTest](g, session, "bool-test") defer session.Close() _, err = namedCache.Put(ctx, test1.ID, test1) @@ -189,7 +189,7 @@ func TestTouchProcessor(t *testing.T) { session, err := utils.GetSession() g.Expect(err).ShouldNot(gomega.HaveOccurred()) - namedCache := utils.GetNamedCache[int, utils.Person](g, session, "touch") + namedCache := GetNamedCache[int, utils.Person](g, session, "touch") defer session.Close() @@ -197,7 +197,7 @@ func TestTouchProcessor(t *testing.T) { _, err = namedCache.Put(ctx, person1.ID, person1) g.Expect(err).NotTo(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.BeNil()) - utils.AssertSize[int, utils.Person](g, namedCache, 1) + AssertSize[int, utils.Person](g, namedCache, 1) // sleep for 6 seconds and the entry should still be there time.Sleep(6 * time.Second) diff --git a/test/e2e/standalone/named_map_test.go b/test/e2e/standalone/named_map_test.go index 3ad5f37a..e76a87fc 100644 --- a/test/e2e/standalone/named_map_test.go +++ b/test/e2e/standalone/named_map_test.go @@ -59,44 +59,44 @@ func TestBasicCrudOperationsVariousTypes(t *testing.T) { g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() - utils.RunKeyValueTest[int, string](g, getNewNamedMap[int, string](g, session, "c1"), 1, "Tim") - utils.RunKeyValueTest[int, utils.Person](g, getNewNamedMap[int, utils.Person](g, session, "c2"), 1, utils.Person{ID: 1, Name: "Tim"}) - utils.RunKeyValueTest[int, float32](g, getNewNamedMap[int, float32](g, session, "c3"), 1, float32(1.123)) - utils.RunKeyValueTest[int, float64](g, getNewNamedMap[int, float64](g, session, "c4"), 1, 1.123) - utils.RunKeyValueTest[int, int](g, getNewNamedMap[int, int](g, session, "c5"), 1, 1) - utils.RunKeyValueTest[int, int16](g, getNewNamedMap[int, int16](g, session, "c7"), 1, 10) - utils.RunKeyValueTest[int, int32](g, getNewNamedMap[int, int32](g, session, "c8"), 1, 1333) - utils.RunKeyValueTest[int, int64](g, getNewNamedMap[int, int64](g, session, "c9"), 1, 1333) - utils.RunKeyValueTest[int, bool](g, getNewNamedMap[int, bool](g, session, "c10"), 1, false) - utils.RunKeyValueTest[int, bool](g, getNewNamedMap[int, bool](g, session, "c11"), 1, true) - utils.RunKeyValueTest[int, byte](g, getNewNamedMap[int, byte](g, session, "c12"), 1, byte(22)) - utils.RunKeyValueTest[string, utils.Person](g, getNewNamedMap[string, utils.Person](g, session, "c13"), "k1", utils.Person{ID: 1, Name: "Tim"}) - utils.RunKeyValueTest[string, string](g, getNewNamedMap[string, string](g, session, "c14"), "k1", "value1") - utils.RunKeyValueTest[int, utils.Person](g, getNewNamedMap[int, utils.Person](g, session, "c15"), 1, + RunKeyValueTest[int, string](g, getNewNamedMap[int, string](g, session, "c1"), 1, "Tim") + RunKeyValueTest[int, utils.Person](g, getNewNamedMap[int, utils.Person](g, session, "c2"), 1, utils.Person{ID: 1, Name: "Tim"}) + RunKeyValueTest[int, float32](g, getNewNamedMap[int, float32](g, session, "c3"), 1, float32(1.123)) + RunKeyValueTest[int, float64](g, getNewNamedMap[int, float64](g, session, "c4"), 1, 1.123) + RunKeyValueTest[int, int](g, getNewNamedMap[int, int](g, session, "c5"), 1, 1) + RunKeyValueTest[int, int16](g, getNewNamedMap[int, int16](g, session, "c7"), 1, 10) + RunKeyValueTest[int, int32](g, getNewNamedMap[int, int32](g, session, "c8"), 1, 1333) + RunKeyValueTest[int, int64](g, getNewNamedMap[int, int64](g, session, "c9"), 1, 1333) + RunKeyValueTest[int, bool](g, getNewNamedMap[int, bool](g, session, "c10"), 1, false) + RunKeyValueTest[int, bool](g, getNewNamedMap[int, bool](g, session, "c11"), 1, true) + RunKeyValueTest[int, byte](g, getNewNamedMap[int, byte](g, session, "c12"), 1, byte(22)) + RunKeyValueTest[string, utils.Person](g, getNewNamedMap[string, utils.Person](g, session, "c13"), "k1", utils.Person{ID: 1, Name: "Tim"}) + RunKeyValueTest[string, string](g, getNewNamedMap[string, string](g, session, "c14"), "k1", "value1") + RunKeyValueTest[int, utils.Person](g, getNewNamedMap[int, utils.Person](g, session, "c15"), 1, utils.Person{ID: 1, Name: "Tim", HomeAddress: utils.Address{Address1: "a1", Address2: "a2", City: "Perth", State: "WA", PostCode: 6000}}) - utils.RunKeyValueTest[int, []string](g, getNewNamedMap[int, []string](g, session, "c16"), 1, + RunKeyValueTest[int, []string](g, getNewNamedMap[int, []string](g, session, "c16"), 1, []string{"a", "b", "c"}) - utils.RunKeyValueTest[int, map[int]string](g, getNewNamedMap[int, map[int]string](g, session, "c17"), 1, + RunKeyValueTest[int, map[int]string](g, getNewNamedMap[int, map[int]string](g, session, "c17"), 1, map[int]string{1: "one", 2: "two", 3: "three"}) - utils.RunKeyValueTest[int, string](g, getNewNamedCache[int, string](g, session, "c1"), 1, "Tim") - utils.RunKeyValueTest[int, utils.Person](g, getNewNamedCache[int, utils.Person](g, session, "c2"), 1, utils.Person{ID: 1, Name: "Tim"}) - utils.RunKeyValueTest[int, float32](g, getNewNamedCache[int, float32](g, session, "c3"), 1, float32(1.123)) - utils.RunKeyValueTest[int, float64](g, getNewNamedCache[int, float64](g, session, "c4"), 1, 1.123) - utils.RunKeyValueTest[int, int](g, getNewNamedCache[int, int](g, session, "c5"), 1, 1) - utils.RunKeyValueTest[int, int16](g, getNewNamedCache[int, int16](g, session, "c7"), 1, 10) - utils.RunKeyValueTest[int, int32](g, getNewNamedCache[int, int32](g, session, "c8"), 1, 1333) - utils.RunKeyValueTest[int, int64](g, getNewNamedCache[int, int64](g, session, "c9"), 1, 1333) - utils.RunKeyValueTest[int, bool](g, getNewNamedCache[int, bool](g, session, "c10"), 1, false) - utils.RunKeyValueTest[int, bool](g, getNewNamedCache[int, bool](g, session, "c11"), 1, true) - utils.RunKeyValueTest[int, byte](g, getNewNamedCache[int, byte](g, session, "c12"), 1, byte(22)) - utils.RunKeyValueTest[string, utils.Person](g, getNewNamedCache[string, utils.Person](g, session, "c13"), "k1", utils.Person{ID: 1, Name: "Tim"}) - utils.RunKeyValueTest[string, string](g, getNewNamedCache[string, string](g, session, "c14"), "k1", "value1") - utils.RunKeyValueTest[int, utils.Person](g, getNewNamedCache[int, utils.Person](g, session, "c15"), 1, + RunKeyValueTest[int, string](g, getNewNamedCache[int, string](g, session, "c1"), 1, "Tim") + RunKeyValueTest[int, utils.Person](g, getNewNamedCache[int, utils.Person](g, session, "c2"), 1, utils.Person{ID: 1, Name: "Tim"}) + RunKeyValueTest[int, float32](g, getNewNamedCache[int, float32](g, session, "c3"), 1, float32(1.123)) + RunKeyValueTest[int, float64](g, getNewNamedCache[int, float64](g, session, "c4"), 1, 1.123) + RunKeyValueTest[int, int](g, getNewNamedCache[int, int](g, session, "c5"), 1, 1) + RunKeyValueTest[int, int16](g, getNewNamedCache[int, int16](g, session, "c7"), 1, 10) + RunKeyValueTest[int, int32](g, getNewNamedCache[int, int32](g, session, "c8"), 1, 1333) + RunKeyValueTest[int, int64](g, getNewNamedCache[int, int64](g, session, "c9"), 1, 1333) + RunKeyValueTest[int, bool](g, getNewNamedCache[int, bool](g, session, "c10"), 1, false) + RunKeyValueTest[int, bool](g, getNewNamedCache[int, bool](g, session, "c11"), 1, true) + RunKeyValueTest[int, byte](g, getNewNamedCache[int, byte](g, session, "c12"), 1, byte(22)) + RunKeyValueTest[string, utils.Person](g, getNewNamedCache[string, utils.Person](g, session, "c13"), "k1", utils.Person{ID: 1, Name: "Tim"}) + RunKeyValueTest[string, string](g, getNewNamedCache[string, string](g, session, "c14"), "k1", "value1") + RunKeyValueTest[int, utils.Person](g, getNewNamedCache[int, utils.Person](g, session, "c15"), 1, utils.Person{ID: 1, Name: "Tim", HomeAddress: utils.Address{Address1: "a1", Address2: "a2", City: "Perth", State: "WA", PostCode: 6000}}) - utils.RunKeyValueTest[int, []string](g, getNewNamedCache[int, []string](g, session, "c16"), 1, + RunKeyValueTest[int, []string](g, getNewNamedCache[int, []string](g, session, "c16"), 1, []string{"a", "b", "c"}) - utils.RunKeyValueTest[int, map[int]string](g, getNewNamedCache[int, map[int]string](g, session, "c17"), 1, + RunKeyValueTest[int, map[int]string](g, getNewNamedCache[int, map[int]string](g, session, "c17"), 1, map[int]string{1: "one", 2: "two", 3: "three"}) } @@ -161,8 +161,8 @@ func TestBasicCrudOperationsVariousTypesWithStructKey(t *testing.T) { account := Account{AccountID: 100, AccountType: "savings", Name: "John Doe", Balance: 100_000} - utils.RunKeyValueTest[AccountKey, Account](g, getNewNamedMap[AccountKey, Account](g, session, "key-map"), account.GetKey(), account) - utils.RunKeyValueTest[AccountKey, Account](g, getNewNamedCache[AccountKey, Account](g, session, "key-cache"), account.GetKey(), account) + RunKeyValueTest[AccountKey, Account](g, getNewNamedMap[AccountKey, Account](g, session, "key-map"), account.GetKey(), account) + RunKeyValueTest[AccountKey, Account](g, getNewNamedCache[AccountKey, Account](g, session, "key-cache"), account.GetKey(), account) } // TestInvocationTimeoutAndTruncate tests running an entry processor with a timeout and then truncate caching. @@ -224,57 +224,57 @@ func TestBasicOperationsAgainstMapAndCache(t *testing.T) { nameMap coherence.NamedMap[int, utils.Person] test func(t *testing.T, namedCache coherence.NamedMap[int, utils.Person]) }{ - {"NamedMapCrudTest", utils.GetNamedMap[int, utils.Person](g, session, "people-map"), RunTestBasicCrudOperations}, - {"NamedCacheCrudTest", utils.GetNamedCache[int, utils.Person](g, session, "people-cache"), RunTestBasicCrudOperations}, - {"NamedMapRunTestGetOrDefault", utils.GetNamedMap[int, utils.Person](g, session, "get-or-default-map"), RunTestGetOrDefault}, - {"NamedCacheRunTestGetOrDefault", utils.GetNamedCache[int, utils.Person](g, session, "get-or-default-cache"), RunTestGetOrDefault}, - {"NamedMapRunTestContainsKey", utils.GetNamedMap[int, utils.Person](g, session, "contains-key-map"), RunTestContainsKey}, - {"NamedCacheRunTestContainsKey", utils.GetNamedCache[int, utils.Person](g, session, "contains-key-cache"), RunTestContainsKey}, - {"NamedMapRunTestPutIfAbsent", utils.GetNamedMap[int, utils.Person](g, session, "put-if-absent-map"), RunTestPutIfAbsent}, - {"NamedCacheRunTestPutIfAbsent", utils.GetNamedCache[int, utils.Person](g, session, "put-of-absent-cache"), RunTestPutIfAbsent}, - {"NamedMapRunTestClearAndIsEmpty", utils.GetNamedMap[int, utils.Person](g, session, "clear-map"), RunTestClearAndIsEmpty}, - {"NamedCacheRunTestClearAndIsEmpty", utils.GetNamedCache[int, utils.Person](g, session, "clear-cache"), RunTestClearAndIsEmpty}, - {"NamedMapRunTestTruncateAndDestroy", utils.GetNamedMap[int, utils.Person](g, session, "truncate-map"), RunTestTruncateAndDestroy}, - {"NamedCacheRunTestTruncateAndDestroy", utils.GetNamedCache[int, utils.Person](g, session, "truncate-cache"), RunTestTruncateAndDestroy}, - {"NamedMapRunTestReplace", utils.GetNamedMap[int, utils.Person](g, session, "replace-map"), RunTestReplace}, - {"NamedCacheRunTestReplace", utils.GetNamedCache[int, utils.Person](g, session, "replace-cache"), RunTestReplace}, - {"NamedMapRunTestReplaceMapping", utils.GetNamedMap[int, utils.Person](g, session, "replace-mapping-map"), RunTestReplaceMapping}, - {"NamedCacheRunTestReplaceMapping", utils.GetNamedCache[int, utils.Person](g, session, "replace-mapping-cache"), RunTestReplaceMapping}, - {"NamedMapRunTestRemoveMapping", utils.GetNamedMap[int, utils.Person](g, session, "remove-mapping-map"), RunTestRemoveMapping}, - {"NamedCacheRunTestRemoveMapping", utils.GetNamedCache[int, utils.Person](g, session, "remove-mapping-cache"), RunTestRemoveMapping}, - {"NamedMapRunTestPutAll", utils.GetNamedMap[int, utils.Person](g, session, "put-all-map"), RunTestPutAll}, - {"NamedCacheRunTestPutAll", utils.GetNamedCache[int, utils.Person](g, session, "put-all-cache"), RunTestPutAll}, - {"NamedMapRunTestContainsValue", utils.GetNamedMap[int, utils.Person](g, session, "contains-value-map"), RunTestContainsValue}, - {"NamedCacheRunTestContainsValue", utils.GetNamedCache[int, utils.Person](g, session, "contains-value-cache"), RunTestContainsValue}, - {"NamedMapRunTestContainsEntry", utils.GetNamedMap[int, utils.Person](g, session, "contains-entry-map"), RunTestContainsEntry}, - {"NamedCacheRunTestContainsEntry", utils.GetNamedCache[int, utils.Person](g, session, "contains-entry-cache"), RunTestContainsEntry}, - {"NamedMapRunTestValuesFilter", utils.GetNamedMap[int, utils.Person](g, session, "values-filter-map"), RunTestValuesFilter}, - {"NamedCacheRunTestValuesFilter", utils.GetNamedCache[int, utils.Person](g, session, "values-filter-cache"), RunTestValuesFilter}, - {"NamedMapRunTestEntrySetFilter", utils.GetNamedMap[int, utils.Person](g, session, "entryset-filter-map"), RunTestEntrySetFilter}, - {"NamedCacheRunTestEntrySetFilter", utils.GetNamedCache[int, utils.Person](g, session, "entryset-filter-cache"), RunTestEntrySetFilter}, - {"NamedMapRunTestEntrySetFilterWithComparator", utils.GetNamedMap[int, utils.Person](g, session, "entryset-filter-map-comparator"), RunTestEntrySetFilterWithComparator}, - {"NamedCacheRunTestEntrySetFilterWithComparator", utils.GetNamedCache[int, utils.Person](g, session, "entryset-filter-cache-comparator"), RunTestEntrySetFilterWithComparator}, - {"NamedCacheRunTestEntrySetFilterWithComparatorStream", utils.GetNamedCache[int, utils.Person](g, session, "entryset-filter-cache-comparator-stream"), RunTestEntrySetFilterWithComparatorStream}, - {"NamedMapRunTestKeySetFilter", utils.GetNamedMap[int, utils.Person](g, session, "keyset-map"), RunTestKeySetFilter}, - {"NamedCacheRunTestKeySetFilter", utils.GetNamedCache[int, utils.Person](g, session, "keyset-cache"), RunTestKeySetFilter}, - {"NamedMapRunTestGetAll", utils.GetNamedMap[int, utils.Person](g, session, "getall-filter-map"), RunTestGetAll}, - {"NamedCacheRunTestGetAll", utils.GetNamedCache[int, utils.Person](g, session, "getall-filter-cache"), RunTestGetAll}, - {"NamedMapRunTestInvokeAll", utils.GetNamedMap[int, utils.Person](g, session, "invokeall-keys-map"), RunTestInvokeAllKeysAndFilter}, - {"NamedCacheRunTestInvokeAll", utils.GetNamedCache[int, utils.Person](g, session, "invokeall-keys-cache"), RunTestInvokeAllKeysAndFilter}, - {"NamedMapRunTestKeySet", utils.GetNamedMap[int, utils.Person](g, session, "keyset-map"), RunTestKeySetLong}, - {"NamedCacheRunTestKeySet", utils.GetNamedCache[int, utils.Person](g, session, "keyset-cache"), RunTestKeySetLong}, - {"NamedMapRunTestKeySetShort", utils.GetNamedMap[int, utils.Person](g, session, "keyset-map-short"), RunTestKeySetShort}, - {"NamedCacheRunTestKeySetShort", utils.GetNamedCache[int, utils.Person](g, session, "keyset-cache-short"), RunTestKeySetShort}, - {"NamedMapRunTestEntrySet", utils.GetNamedMap[int, utils.Person](g, session, "entryset-map"), RunTestEntrySetLong}, - {"NamedCacheRunTestEntrySet", utils.GetNamedCache[int, utils.Person](g, session, "entryset-cache"), RunTestEntrySetLong}, - {"NamedMapRunTestEntrySetShort", utils.GetNamedMap[int, utils.Person](g, session, "entryset-map-short"), RunTestEntrySetShort}, - {"NamedCacheRunTestEntrySetShort", utils.GetNamedCache[int, utils.Person](g, session, "entryset-cache-short"), RunTestEntrySetShort}, - {"NamedMapRunTestValues", utils.GetNamedMap[int, utils.Person](g, session, "values-map-short"), RunTestValuesShort}, - {"NamedCacheRunTestValues", utils.GetNamedCache[int, utils.Person](g, session, "values-cache-short"), RunTestValuesShort}, - {"NamedMapRunTestValues", utils.GetNamedMap[int, utils.Person](g, session, "values-map"), RunTestValuesLong}, - {"NamedCacheRunTestValues", utils.GetNamedCache[int, utils.Person](g, session, "values-cache"), RunTestValuesLong}, - {"NamedMapRunTestIsReady", utils.GetNamedMap[int, utils.Person](g, session, "is-ready-map"), RunTestIsReady}, - {"NamedCacheRunTestIsReady", utils.GetNamedCache[int, utils.Person](g, session, "is-ready-cache"), RunTestIsReady}, + {"NamedMapCrudTest", GetNamedMap[int, utils.Person](g, session, "people-map"), RunTestBasicCrudOperations}, + {"NamedCacheCrudTest", GetNamedCache[int, utils.Person](g, session, "people-cache"), RunTestBasicCrudOperations}, + {"NamedMapRunTestGetOrDefault", GetNamedMap[int, utils.Person](g, session, "get-or-default-map"), RunTestGetOrDefault}, + {"NamedCacheRunTestGetOrDefault", GetNamedCache[int, utils.Person](g, session, "get-or-default-cache"), RunTestGetOrDefault}, + {"NamedMapRunTestContainsKey", GetNamedMap[int, utils.Person](g, session, "contains-key-map"), RunTestContainsKey}, + {"NamedCacheRunTestContainsKey", GetNamedCache[int, utils.Person](g, session, "contains-key-cache"), RunTestContainsKey}, + {"NamedMapRunTestPutIfAbsent", GetNamedMap[int, utils.Person](g, session, "put-if-absent-map"), RunTestPutIfAbsent}, + {"NamedCacheRunTestPutIfAbsent", GetNamedCache[int, utils.Person](g, session, "put-of-absent-cache"), RunTestPutIfAbsent}, + {"NamedMapRunTestClearAndIsEmpty", GetNamedMap[int, utils.Person](g, session, "clear-map"), RunTestClearAndIsEmpty}, + {"NamedCacheRunTestClearAndIsEmpty", GetNamedCache[int, utils.Person](g, session, "clear-cache"), RunTestClearAndIsEmpty}, + {"NamedMapRunTestTruncateAndDestroy", GetNamedMap[int, utils.Person](g, session, "truncate-map"), RunTestTruncateAndDestroy}, + {"NamedCacheRunTestTruncateAndDestroy", GetNamedCache[int, utils.Person](g, session, "truncate-cache"), RunTestTruncateAndDestroy}, + {"NamedMapRunTestReplace", GetNamedMap[int, utils.Person](g, session, "replace-map"), RunTestReplace}, + {"NamedCacheRunTestReplace", GetNamedCache[int, utils.Person](g, session, "replace-cache"), RunTestReplace}, + {"NamedMapRunTestReplaceMapping", GetNamedMap[int, utils.Person](g, session, "replace-mapping-map"), RunTestReplaceMapping}, + {"NamedCacheRunTestReplaceMapping", GetNamedCache[int, utils.Person](g, session, "replace-mapping-cache"), RunTestReplaceMapping}, + {"NamedMapRunTestRemoveMapping", GetNamedMap[int, utils.Person](g, session, "remove-mapping-map"), RunTestRemoveMapping}, + {"NamedCacheRunTestRemoveMapping", GetNamedCache[int, utils.Person](g, session, "remove-mapping-cache"), RunTestRemoveMapping}, + {"NamedMapRunTestPutAll", GetNamedMap[int, utils.Person](g, session, "put-all-map"), RunTestPutAll}, + {"NamedCacheRunTestPutAll", GetNamedCache[int, utils.Person](g, session, "put-all-cache"), RunTestPutAll}, + {"NamedMapRunTestContainsValue", GetNamedMap[int, utils.Person](g, session, "contains-value-map"), RunTestContainsValue}, + {"NamedCacheRunTestContainsValue", GetNamedCache[int, utils.Person](g, session, "contains-value-cache"), RunTestContainsValue}, + {"NamedMapRunTestContainsEntry", GetNamedMap[int, utils.Person](g, session, "contains-entry-map"), RunTestContainsEntry}, + {"NamedCacheRunTestContainsEntry", GetNamedCache[int, utils.Person](g, session, "contains-entry-cache"), RunTestContainsEntry}, + {"NamedMapRunTestValuesFilter", GetNamedMap[int, utils.Person](g, session, "values-filter-map"), RunTestValuesFilter}, + {"NamedCacheRunTestValuesFilter", GetNamedCache[int, utils.Person](g, session, "values-filter-cache"), RunTestValuesFilter}, + {"NamedMapRunTestEntrySetFilter", GetNamedMap[int, utils.Person](g, session, "entryset-filter-map"), RunTestEntrySetFilter}, + {"NamedCacheRunTestEntrySetFilter", GetNamedCache[int, utils.Person](g, session, "entryset-filter-cache"), RunTestEntrySetFilter}, + {"NamedMapRunTestEntrySetFilterWithComparator", GetNamedMap[int, utils.Person](g, session, "entryset-filter-map-comparator"), RunTestEntrySetFilterWithComparator}, + {"NamedCacheRunTestEntrySetFilterWithComparator", GetNamedCache[int, utils.Person](g, session, "entryset-filter-cache-comparator"), RunTestEntrySetFilterWithComparator}, + {"NamedCacheRunTestEntrySetFilterWithComparatorStream", GetNamedCache[int, utils.Person](g, session, "entryset-filter-cache-comparator-stream"), RunTestEntrySetFilterWithComparatorStream}, + {"NamedMapRunTestKeySetFilter", GetNamedMap[int, utils.Person](g, session, "keyset-map"), RunTestKeySetFilter}, + {"NamedCacheRunTestKeySetFilter", GetNamedCache[int, utils.Person](g, session, "keyset-cache"), RunTestKeySetFilter}, + {"NamedMapRunTestGetAll", GetNamedMap[int, utils.Person](g, session, "getall-filter-map"), RunTestGetAll}, + {"NamedCacheRunTestGetAll", GetNamedCache[int, utils.Person](g, session, "getall-filter-cache"), RunTestGetAll}, + {"NamedMapRunTestInvokeAll", GetNamedMap[int, utils.Person](g, session, "invokeall-keys-map"), RunTestInvokeAllKeysAndFilter}, + {"NamedCacheRunTestInvokeAll", GetNamedCache[int, utils.Person](g, session, "invokeall-keys-cache"), RunTestInvokeAllKeysAndFilter}, + {"NamedMapRunTestKeySet", GetNamedMap[int, utils.Person](g, session, "keyset-map"), RunTestKeySetLong}, + {"NamedCacheRunTestKeySet", GetNamedCache[int, utils.Person](g, session, "keyset-cache"), RunTestKeySetLong}, + {"NamedMapRunTestKeySetShort", GetNamedMap[int, utils.Person](g, session, "keyset-map-short"), RunTestKeySetShort}, + {"NamedCacheRunTestKeySetShort", GetNamedCache[int, utils.Person](g, session, "keyset-cache-short"), RunTestKeySetShort}, + {"NamedMapRunTestEntrySet", GetNamedMap[int, utils.Person](g, session, "entryset-map"), RunTestEntrySetLong}, + {"NamedCacheRunTestEntrySet", GetNamedCache[int, utils.Person](g, session, "entryset-cache"), RunTestEntrySetLong}, + {"NamedMapRunTestEntrySetShort", GetNamedMap[int, utils.Person](g, session, "entryset-map-short"), RunTestEntrySetShort}, + {"NamedCacheRunTestEntrySetShort", GetNamedCache[int, utils.Person](g, session, "entryset-cache-short"), RunTestEntrySetShort}, + {"NamedMapRunTestValues", GetNamedMap[int, utils.Person](g, session, "values-map-short"), RunTestValuesShort}, + {"NamedCacheRunTestValues", GetNamedCache[int, utils.Person](g, session, "values-cache-short"), RunTestValuesShort}, + {"NamedMapRunTestValues", GetNamedMap[int, utils.Person](g, session, "values-map"), RunTestValuesLong}, + {"NamedCacheRunTestValues", GetNamedCache[int, utils.Person](g, session, "values-cache"), RunTestValuesLong}, + {"NamedMapRunTestIsReady", GetNamedMap[int, utils.Person](g, session, "is-ready-map"), RunTestIsReady}, + {"NamedCacheRunTestIsReady", GetNamedCache[int, utils.Person](g, session, "is-ready-cache"), RunTestIsReady}, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { @@ -353,7 +353,7 @@ func RunTestBasicCrudOperations(t *testing.T, namedMap coherence.NamedMap[int, u result, err = namedMap.Get(ctx, person1.ID) g.Expect(err).ShouldNot(gomega.HaveOccurred()) g.Expect(result).To(gomega.Not(gomega.BeNil())) - utils.AssertPersonResult(g, *result, person1) + AssertPersonResult(g, *result, person1) // update the name to "Timothy" person1.Name = "Timothy" @@ -364,11 +364,11 @@ func RunTestBasicCrudOperations(t *testing.T, namedMap coherence.NamedMap[int, u result, err = namedMap.Get(ctx, person1.ID) g.Expect(err).ShouldNot(gomega.HaveOccurred()) - utils.AssertPersonResult(g, *result, person1) + AssertPersonResult(g, *result, person1) oldValue, err = namedMap.Remove(ctx, person1.ID) g.Expect(err).ShouldNot(gomega.HaveOccurred()) - utils.AssertPersonResult(g, *oldValue, person1) + AssertPersonResult(g, *oldValue, person1) } func TestMultipleCallsToNamedMap(t *testing.T) { @@ -411,7 +411,7 @@ func TestMultipleCallsToNamedMap(t *testing.T) { namedMap3, err := coherence.GetNamedMap[int, utils.Person](session, "map-2") g.Expect(err).NotTo(gomega.HaveOccurred()) - utils.AssertSize(g, namedMap3, 0) + AssertSize(g, namedMap3, 0) // try and retrieve a NamedMap that is for the same cache but different type, this should cause error _, err = coherence.GetNamedMap[int, string](session, "map-2") @@ -488,7 +488,7 @@ func RunTestGetOrDefault(t *testing.T, namedMap coherence.NamedMap[int, utils.Pe result, err = namedMap.GetOrDefault(ctx, 10, utils.Person{ID: 111, Name: "Not this one"}) g.Expect(err).ShouldNot(gomega.HaveOccurred()) g.Expect(result).To(gomega.Not(gomega.BeNil())) - utils.AssertPersonResult(g, *result, person1) + AssertPersonResult(g, *result, person1) } func RunTestContainsKey(t *testing.T, namedMap coherence.NamedMap[int, utils.Person]) { @@ -605,14 +605,14 @@ func RunTestPutIfAbsent(t *testing.T, namedMap coherence.NamedMap[int, utils.Per g.Expect(result).To(gomega.Not(gomega.BeNil())) // assert the Value returned is the existing entry - utils.AssertPersonResult(g, *result, person1) + AssertPersonResult(g, *result, person1) // ensure a Get for the person1.ID returns the original person // and not the attempted update result, err = namedMap.Get(ctx, person1.ID) g.Expect(err).ShouldNot(gomega.HaveOccurred()) g.Expect(result).To(gomega.Not(gomega.BeNil())) - utils.AssertPersonResult(g, *result, person1) + AssertPersonResult(g, *result, person1) } func RunTestClearAndIsEmpty(t *testing.T, namedMap coherence.NamedMap[int, utils.Person]) { @@ -682,13 +682,13 @@ func RunTestReplace(t *testing.T, namedMap coherence.NamedMap[int, utils.Person] g.Expect(err).NotTo(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.BeNil()) - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) // this should work as it's mapped to any Value oldValue, err = namedMap.Replace(ctx, 1, personReplace) g.Expect(err).ShouldNot(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.Not(gomega.BeNil())) - utils.AssertPersonResult(g, *oldValue, person1) + AssertPersonResult(g, *oldValue, person1) } func RunTestReplaceMapping(t *testing.T, namedMap coherence.NamedMap[int, utils.Person]) { @@ -713,7 +713,7 @@ func RunTestReplaceMapping(t *testing.T, namedMap coherence.NamedMap[int, utils. g.Expect(err).NotTo(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.BeNil()) - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) // value exists but doesn't match so should return false result, err = namedMap.ReplaceMapping(ctx, 1, personReplace, person1) @@ -749,13 +749,13 @@ func RunTestRemoveMapping(t *testing.T, namedMap coherence.NamedMap[int, utils.P // add a Key with a Value that will not match _, err = namedMap.Put(ctx, 1, person2) g.Expect(err).NotTo(gomega.HaveOccurred()) - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) // remove a mapping that doesn't match removed, err = namedMap.RemoveMapping(ctx, 1, person1) g.Expect(err).ShouldNot(gomega.HaveOccurred()) g.Expect(removed).Should(gomega.Equal(false)) - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) // set the Key to a Value that will match _, err = namedMap.Put(ctx, 1, person1) @@ -764,7 +764,7 @@ func RunTestRemoveMapping(t *testing.T, namedMap coherence.NamedMap[int, utils.P removed, err = namedMap.RemoveMapping(ctx, 1, person1) g.Expect(err).ShouldNot(gomega.HaveOccurred()) g.Expect(removed).Should(gomega.Equal(true)) - utils.AssertSize(g, namedMap, 0) + AssertSize(g, namedMap, 0) } var peopleData = map[int]utils.Person{ @@ -915,7 +915,7 @@ func RunTestEntrySetFilterWithComparatorStream(t *testing.T, namedMap coherence. return } - utils.ClearNamedMap(g, namedMap) + ClearNamedMap(g, namedMap) // populate the cache for i := 1; i <= maxPeople; i++ { @@ -927,7 +927,7 @@ func RunTestEntrySetFilterWithComparatorStream(t *testing.T, namedMap coherence. g.Expect(err).NotTo(gomega.HaveOccurred()) } - utils.AssertSize(g, namedMap, maxPeople) + AssertSize(g, namedMap, maxPeople) // only retrieve 300 entries and then skip out ch := coherence.EntrySetFilterWithComparator(ctx, namedMap, filters.Always(), comparatorAscending) diff --git a/test/e2e/standalone/near_cache_test.go b/test/e2e/standalone/near_cache_test.go index e40c8242..2bf3c9b1 100644 --- a/test/e2e/standalone/near_cache_test.go +++ b/test/e2e/standalone/near_cache_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Oracle and/or its affiliates. + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -85,7 +85,7 @@ func RunTestNearCacheBasic(t *testing.T, namedMap coherence.NamedMap[int, utils. oldValue, err = namedMap.Put(ctx, person1.ID, person1) g.Expect(err).NotTo(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.BeNil()) - utils.AssertSize[int, utils.Person](g, namedMap, 1) + AssertSize[int, utils.Person](g, namedMap, 1) // this should add to the near cache _, err = namedMap.Get(ctx, person1.ID) @@ -110,7 +110,7 @@ func RunTestNearCacheBasic(t *testing.T, namedMap coherence.NamedMap[int, utils. // sleep for 15 seconds, this should expiry the entry and cause re-read utils.Sleep(15) - utils.AssertSize[int, utils.Person](g, namedMap, 1) + AssertSize[int, utils.Person](g, namedMap, 1) _, err = namedMap.Get(ctx, person1.ID) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -120,13 +120,13 @@ func RunTestNearCacheBasic(t *testing.T, namedMap coherence.NamedMap[int, utils. g.Expect(err).NotTo(gomega.HaveOccurred()) g.Expect(namedMap.GetNearCacheStats().Size()).To(gomega.Equal(0)) - utils.AssertSize[int, utils.Person](g, namedMap, 0) + AssertSize[int, utils.Person](g, namedMap, 0) // add new entry and do a get to populate near cache oldValue, err = namedMap.Put(ctx, person1.ID, person1) g.Expect(err).NotTo(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.BeNil()) - utils.AssertSize[int, utils.Person](g, namedMap, 1) + AssertSize[int, utils.Person](g, namedMap, 1) _, err = namedMap.Get(ctx, person1.ID) g.Expect(err).NotTo(gomega.HaveOccurred()) @@ -161,7 +161,7 @@ func RunTestNearCacheGetAll(t *testing.T, namedMap coherence.NamedMap[int, utils // populate err = namedMap.PutAll(ctx, people) g.Expect(err).NotTo(gomega.HaveOccurred()) - utils.AssertSize[int, utils.Person](g, namedMap, 3) + AssertSize[int, utils.Person](g, namedMap, 3) count := 0 // issue a GetAll for all keys, should be no hits @@ -187,7 +187,7 @@ func RunTestNearCacheGetAll(t *testing.T, namedMap coherence.NamedMap[int, utils // add the entries back err = namedMap.PutAll(ctx, people) g.Expect(err).NotTo(gomega.HaveOccurred()) - utils.AssertSize[int, utils.Person](g, namedMap, 3) + AssertSize[int, utils.Person](g, namedMap, 3) // issue a Get for key 1 and 2 only _, err = namedMap.Get(ctx, 1) @@ -229,7 +229,7 @@ func RunTestNearCacheGetAll2(t *testing.T, namedMap coherence.NamedMap[int, util err = namedMap.PutAll(ctx, people) g.Expect(err).NotTo(gomega.HaveOccurred()) - utils.AssertSize[int, utils.Person](g, namedMap, 3) + AssertSize[int, utils.Person](g, namedMap, 3) count := 0 // issue a GetAll for all keys, should be no hits @@ -338,7 +338,7 @@ func RunTestNearCacheWithHighUnits(t *testing.T, namedMap coherence.NamedMap[int g.Expect(err).ShouldNot(gomega.HaveOccurred()) } - utils.AssertSize[int, utils.Person](g, namedMap, 200) + AssertSize[int, utils.Person](g, namedMap, 200) // issue 100 gets to fill the near cache for i := 1; i <= 100; i++ { @@ -383,7 +383,7 @@ func RunTestNearWithClear(t *testing.T, namedMap coherence.NamedMap[int, utils.P _, err = namedMap.Put(ctx, p2.ID, p2) g.Expect(err).ShouldNot(gomega.HaveOccurred()) - utils.AssertSize[int, utils.Person](g, namedMap, 2) + AssertSize[int, utils.Person](g, namedMap, 2) p1Get, err = namedMap.Get(ctx, p1.ID) g.Expect(err).ShouldNot(gomega.HaveOccurred()) @@ -422,7 +422,7 @@ func RunTestNearCacheWithHighUnitsAccess(t *testing.T, namedMap coherence.NamedM g.Expect(err).ShouldNot(gomega.HaveOccurred()) } - utils.AssertSize[int, utils.Person](g, namedMap, 200) + AssertSize[int, utils.Person](g, namedMap, 200) // issue 50 gets, should add entries to the near cache for i := 1; i <= 50; i++ { @@ -481,7 +481,7 @@ func RunTestNearCacheWithHighUnitsMemory(t *testing.T, namedMap coherence.NamedM } err = namedMap.PutAll(ctx, buffer) g.Expect(err).ShouldNot(gomega.HaveOccurred()) - utils.AssertSize[int, utils.Person](g, namedMap, 5_000) + AssertSize[int, utils.Person](g, namedMap, 5_000) // issue 10_000 gets to fill the near cache for i := 1; i <= 5_000; i++ { @@ -827,7 +827,7 @@ func RunTestNearCacheReplaces(t *testing.T, namedMap coherence.NamedMap[int, uti // clear the cache err = namedMap.Clear(ctx) g.Expect(err).ShouldNot(gomega.HaveOccurred()) - utils.AssertSize[int, utils.Person](g, namedMap, 0) + AssertSize[int, utils.Person](g, namedMap, 0) utils.Sleep(5) g.Expect(namedMap.GetNearCacheStats().Size()).To(gomega.Equal(0)) diff --git a/test/e2e/standalone/processor_test.go b/test/e2e/standalone/processor_test.go index e7bef5df..152fb9cb 100644 --- a/test/e2e/standalone/processor_test.go +++ b/test/e2e/standalone/processor_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024 Oracle and/or its affiliates. + * Copyright (c) 2023, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -29,26 +29,26 @@ func TestProcessorAgainstMapAndCache(t *testing.T) { nameMap coherence.NamedMap[int, utils.Person] test func(t *testing.T, namedCache coherence.NamedMap[int, utils.Person]) }{ - {"NamedMapRunTestInvokeIncrement", utils.GetNamedMap[int, utils.Person](g, session, "increment-map"), RunTestInvokeIncrement}, - {"NamedCacheRunTestInvokeIncrement", utils.GetNamedCache[int, utils.Person](g, session, "increment-cache"), RunTestInvokeIncrement}, - {"NamedMapRunTestInvokeMultiply", utils.GetNamedMap[int, utils.Person](g, session, "multiply-map"), RunTestInvokeMultiply}, - {"NamedCacheRunTestInvokeMultiply", utils.GetNamedCache[int, utils.Person](g, session, "multiply-cache"), RunTestInvokeMultiply}, - {"NamedMapRunTestInvokeConditionalRemove", utils.GetNamedMap[int, utils.Person](g, session, "cond-remove-map"), RunTestInvokeConditionalRemove}, - {"NamedCacheRunTestInvokeConditionalRemove", utils.GetNamedCache[int, utils.Person](g, session, "cond-remove-cache"), RunTestInvokeConditionalRemove}, - {"NamedMapRunTestInvokeConditionalPut", utils.GetNamedMap[int, utils.Person](g, session, "cond-put-map"), RunTestInvokeConditionalPut}, - {"NamedCacheRunTestInvokeConditionalPut", utils.GetNamedCache[int, utils.Person](g, session, "cond-put-cache"), RunTestInvokeConditionalPut}, - {"NamedMapRunTestExtractProcessor", utils.GetNamedMap[int, utils.Person](g, session, "extractor-map"), RunTestExtractProcessor}, - {"NamedCacheRunTestExtractProcessor", utils.GetNamedCache[int, utils.Person](g, session, "extractor-cache"), RunTestExtractProcessor}, - {"NamedMapRunTestInvokeUpdater", utils.GetNamedMap[int, utils.Person](g, session, "updater-map"), RunTestInvokeUpdater}, - {"NamedCacheRunTestInvokeUpdater", utils.GetNamedCache[int, utils.Person](g, session, "updater-cache"), RunTestInvokeUpdater}, - {"NamedMapRunTestMethodInvocationProcessor", utils.GetNamedMap[int, utils.Person](g, session, "mip-map"), RunTestMethodInvocationProcessor}, - {"NamedCacheRunTestMethodInvocationProcessor", utils.GetNamedCache[int, utils.Person](g, session, "mip-cache"), RunTestMethodInvocationProcessor}, - {"NamedMapRunTestMethodInvocationProcessorMutator", utils.GetNamedMap[int, utils.Person](g, session, "mip-mutate-map"), RunTestMethodInvocationProcessorMutator}, - {"NamedCacheRunTestMethodInvocationProcessorMutator", utils.GetNamedCache[int, utils.Person](g, session, "mip-mutate-cache"), RunTestMethodInvocationProcessorMutator}, - {"NamedMapRunTestInvokeConditionalPutAll", utils.GetNamedMap[int, utils.Person](g, session, "map-conditional-put-all"), RunTestInvokeConditionalPutAll}, - {"NamedCacheRunTestInvokeConditionalPutAll", utils.GetNamedCache[int, utils.Person](g, session, "cache-conditional-put-all"), RunTestInvokeConditionalPutAll}, - {"NamedMapRunTestInvokeAll", utils.GetNamedMap[int, utils.Person](g, session, "map-invoke-all"), RunTestInvokeAll}, - {"NamedCacheRunTestInvokeAll", utils.GetNamedCache[int, utils.Person](g, session, "cache-invoke-all"), RunTestInvokeAll}, + {"NamedMapRunTestInvokeIncrement", GetNamedMap[int, utils.Person](g, session, "increment-map"), RunTestInvokeIncrement}, + {"NamedCacheRunTestInvokeIncrement", GetNamedCache[int, utils.Person](g, session, "increment-cache"), RunTestInvokeIncrement}, + {"NamedMapRunTestInvokeMultiply", GetNamedMap[int, utils.Person](g, session, "multiply-map"), RunTestInvokeMultiply}, + {"NamedCacheRunTestInvokeMultiply", GetNamedCache[int, utils.Person](g, session, "multiply-cache"), RunTestInvokeMultiply}, + {"NamedMapRunTestInvokeConditionalRemove", GetNamedMap[int, utils.Person](g, session, "cond-remove-map"), RunTestInvokeConditionalRemove}, + {"NamedCacheRunTestInvokeConditionalRemove", GetNamedCache[int, utils.Person](g, session, "cond-remove-cache"), RunTestInvokeConditionalRemove}, + {"NamedMapRunTestInvokeConditionalPut", GetNamedMap[int, utils.Person](g, session, "cond-put-map"), RunTestInvokeConditionalPut}, + {"NamedCacheRunTestInvokeConditionalPut", GetNamedCache[int, utils.Person](g, session, "cond-put-cache"), RunTestInvokeConditionalPut}, + {"NamedMapRunTestExtractProcessor", GetNamedMap[int, utils.Person](g, session, "extractor-map"), RunTestExtractProcessor}, + {"NamedCacheRunTestExtractProcessor", GetNamedCache[int, utils.Person](g, session, "extractor-cache"), RunTestExtractProcessor}, + {"NamedMapRunTestInvokeUpdater", GetNamedMap[int, utils.Person](g, session, "updater-map"), RunTestInvokeUpdater}, + {"NamedCacheRunTestInvokeUpdater", GetNamedCache[int, utils.Person](g, session, "updater-cache"), RunTestInvokeUpdater}, + {"NamedMapRunTestMethodInvocationProcessor", GetNamedMap[int, utils.Person](g, session, "mip-map"), RunTestMethodInvocationProcessor}, + {"NamedCacheRunTestMethodInvocationProcessor", GetNamedCache[int, utils.Person](g, session, "mip-cache"), RunTestMethodInvocationProcessor}, + {"NamedMapRunTestMethodInvocationProcessorMutator", GetNamedMap[int, utils.Person](g, session, "mip-mutate-map"), RunTestMethodInvocationProcessorMutator}, + {"NamedCacheRunTestMethodInvocationProcessorMutator", GetNamedCache[int, utils.Person](g, session, "mip-mutate-cache"), RunTestMethodInvocationProcessorMutator}, + {"NamedMapRunTestInvokeConditionalPutAll", GetNamedMap[int, utils.Person](g, session, "map-conditional-put-all"), RunTestInvokeConditionalPutAll}, + {"NamedCacheRunTestInvokeConditionalPutAll", GetNamedCache[int, utils.Person](g, session, "cache-conditional-put-all"), RunTestInvokeConditionalPutAll}, + {"NamedMapRunTestInvokeAll", GetNamedMap[int, utils.Person](g, session, "map-invoke-all"), RunTestInvokeAll}, + {"NamedCacheRunTestInvokeAll", GetNamedCache[int, utils.Person](g, session, "cache-invoke-all"), RunTestInvokeAll}, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { @@ -70,10 +70,10 @@ func TestWithVersionedAgainstMapAndCache(t *testing.T) { nameMap coherence.NamedMap[int, utils.VersionedPerson] test func(t *testing.T, namedCache coherence.NamedMap[int, utils.VersionedPerson]) }{ - {"NamedMapRunTestVersionedPut", utils.GetNamedMap[int, utils.VersionedPerson](g, session, "versioned-put-map"), RunTestVersionedPut}, - {"NamedCacheRunTestVersionedPut", utils.GetNamedCache[int, utils.VersionedPerson](g, session, "versioned-put-cache"), RunTestVersionedPut}, - {"NamedMapRunTestVersionedPutAll", utils.GetNamedMap[int, utils.VersionedPerson](g, session, "versioned-putall-map"), RunTestVersionedPutAll}, - {"NamedCacheRunTestVersionedPutAll", utils.GetNamedCache[int, utils.VersionedPerson](g, session, "versioned-putall-cache"), RunTestVersionedPutAll}, + {"NamedMapRunTestVersionedPut", GetNamedMap[int, utils.VersionedPerson](g, session, "versioned-put-map"), RunTestVersionedPut}, + {"NamedCacheRunTestVersionedPut", GetNamedCache[int, utils.VersionedPerson](g, session, "versioned-put-cache"), RunTestVersionedPut}, + {"NamedMapRunTestVersionedPutAll", GetNamedMap[int, utils.VersionedPerson](g, session, "versioned-putall-map"), RunTestVersionedPutAll}, + {"NamedCacheRunTestVersionedPutAll", GetNamedCache[int, utils.VersionedPerson](g, session, "versioned-putall-cache"), RunTestVersionedPutAll}, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { @@ -95,8 +95,8 @@ func TestAgainstIntAndString(t *testing.T) { nameMap coherence.NamedMap[int, string] test func(t *testing.T, namedCache coherence.NamedMap[int, string]) }{ - {"NamedMapRunTestPreloadProcessor", utils.GetNamedMap[int, string](g, session, "preload"), RunTestPreloadProcessor}, - {"NamedCacheRunTestPreloadProcessor", utils.GetNamedCache[int, string](g, session, "preload"), RunTestPreloadProcessor}, + {"NamedMapRunTestPreloadProcessor", GetNamedMap[int, string](g, session, "preload"), RunTestPreloadProcessor}, + {"NamedCacheRunTestPreloadProcessor", GetNamedCache[int, string](g, session, "preload"), RunTestPreloadProcessor}, } for _, tc := range testCases { t.Run(tc.testName, func(t *testing.T) { @@ -115,14 +115,14 @@ func RunTestPreloadProcessor(t *testing.T, namedMap coherence.NamedMap[int, stri err = namedMap.Clear(ctx) g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - utils.AssertSize(g, namedMap, 0) + AssertSize(g, namedMap, 0) // Preload will cause the cache store to load the value of "Number 1" _, err = coherence.Invoke[int, string, string](ctx, namedMap, 1, processors.Preload()) g.Expect(err).NotTo(gomega.HaveOccurred()) // value should be in cache - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) value, err = namedMap.Get(ctx, 1) g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) @@ -223,7 +223,7 @@ func RunTestVersionedPutAll(t *testing.T, namedMap coherence.NamedMap[int, utils processors.VersionedPutAll(values, true, false)) g.Expect(err).ShouldNot(gomega.HaveOccurred()) - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) } func RunTestExtractProcessor(t *testing.T, namedMap coherence.NamedMap[int, utils.Person]) { @@ -354,7 +354,7 @@ func RunTestInvokeConditionalRemove(t *testing.T, namedMap coherence.NamedMap[in g.Expect(oldValue).To(gomega.BeNil()) // should have been removed - utils.AssertSize(g, namedMap, 0) + AssertSize(g, namedMap, 0) oldValue, err = namedMap.Put(ctx, 1, person) g.Expect(err).ShouldNot(gomega.HaveOccurred()) @@ -366,7 +366,7 @@ func RunTestInvokeConditionalRemove(t *testing.T, namedMap coherence.NamedMap[in g.Expect(oldValue).To(gomega.BeNil()) // should have been removed as age is greater than 5 - utils.AssertSize(g, namedMap, 0) + AssertSize(g, namedMap, 0) oldValue, err = namedMap.Put(ctx, 1, person) g.Expect(err).ShouldNot(gomega.HaveOccurred()) @@ -378,7 +378,7 @@ func RunTestInvokeConditionalRemove(t *testing.T, namedMap coherence.NamedMap[in g.Expect(oldValue).To(gomega.BeNil()) // should not been removed as age is NOT greater than 10 - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) } func RunTestInvokeConditionalPut(t *testing.T, namedMap coherence.NamedMap[int, utils.Person]) { @@ -393,15 +393,15 @@ func RunTestInvokeConditionalPut(t *testing.T, namedMap coherence.NamedMap[int, oldValue, err = coherence.Invoke[int, utils.Person, utils.Person](ctx, namedMap, 1, processors.ConditionalPut[utils.Person](filters.Always(), person)) g.Expect(err).ShouldNot(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.BeNil()) - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) - utils.ClearNamedMap[int, utils.Person](g, namedMap) + ClearNamedMap[int, utils.Person](g, namedMap) // should put as filter is false oldValue, err = coherence.Invoke[int, utils.Person, utils.Person](ctx, namedMap, 1, processors.ConditionalPut[utils.Person](filters.Never(), person)) g.Expect(err).ShouldNot(gomega.HaveOccurred()) g.Expect(oldValue).To(gomega.BeNil()) - utils.AssertSize(g, namedMap, 0) + AssertSize(g, namedMap, 0) } func RunTestInvokeUpdater(t *testing.T, namedMap coherence.NamedMap[int, utils.Person]) { @@ -455,14 +455,14 @@ func RunTestInvokeConditionalPutAll(t *testing.T, namedMap coherence.NamedMap[in // should put as filter is true _, err = coherence.Invoke[int, utils.Person, int](ctx, namedMap, 1, processors.ConditionalPutAll[int, utils.Person](filters.Always(), values)) g.Expect(err).ShouldNot(gomega.HaveOccurred()) - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) - utils.ClearNamedMap[int, utils.Person](g, namedMap) + ClearNamedMap[int, utils.Person](g, namedMap) // should put as filter is false _, err = coherence.Invoke[int, utils.Person, int](ctx, namedMap, 1, processors.ConditionalPutAll[int, utils.Person](filters.Never(), values)) g.Expect(err).ShouldNot(gomega.HaveOccurred()) - utils.AssertSize(g, namedMap, 0) + AssertSize(g, namedMap, 0) } func RunTestInvokeAll(t *testing.T, namedMap coherence.NamedMap[int, utils.Person]) { @@ -522,5 +522,5 @@ func addPerson(g *gomega.WithT, namedMap coherence.NamedMap[int, utils.Person]) _, err := namedMap.Put(ctx, 1, utils.Person{ID: 1, Name: "Tim", Age: 10, Salary: 1000, HomeAddress: utils.Address{Address1: "address1", Address2: "address1", City: "Perth", State: "WA", PostCode: 6000}}) g.Expect(err).ShouldNot(gomega.HaveOccurred()) - utils.AssertSize(g, namedMap, 1) + AssertSize(g, namedMap, 1) } diff --git a/test/e2e/standalone/suite_test.go b/test/e2e/standalone/suite_test.go index 783a7559..60c8123d 100644 --- a/test/e2e/standalone/suite_test.go +++ b/test/e2e/standalone/suite_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -7,11 +7,81 @@ package standalone import ( + "context" + "github.com/onsi/gomega" + "github.com/oracle/coherence-go-client/v2/coherence" "github.com/oracle/coherence-go-client/v2/test/utils" "testing" ) +var localCtx = context.Background() + // The entry point for the test suite func TestMain(m *testing.M) { utils.RunTest(m, 1408, 30000, 8080, true) } + +func GetNamedMapWithScope[K comparable, V any](g *gomega.WithT, session *coherence.Session, cacheName, _ string) coherence.NamedMap[K, V] { + namedCache, err := coherence.GetNamedMap[K, V](session, cacheName) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + err = namedCache.Clear(localCtx) + g.Expect(err).NotTo(gomega.HaveOccurred()) + + return namedCache +} + +func GetNamedCacheWithScope[K comparable, V any](g *gomega.WithT, session *coherence.Session, cacheName, _ string) coherence.NamedCache[K, V] { + namedCache, err := coherence.GetNamedCache[K, V](session, cacheName) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + err = namedCache.Clear(localCtx) + g.Expect(err).NotTo(gomega.HaveOccurred()) + + return namedCache +} + +func GetNamedMap[K comparable, V any](g *gomega.WithT, session *coherence.Session, cacheName string) coherence.NamedMap[K, V] { + return GetNamedMapWithScope[K, V](g, session, cacheName, "") +} + +func GetNamedCache[K comparable, V any](g *gomega.WithT, session *coherence.Session, cacheName string) coherence.NamedCache[K, V] { + return GetNamedCacheWithScope[K, V](g, session, cacheName, "") +} + +func AssertSize[K comparable, V any](g *gomega.WithT, namedMap coherence.NamedMap[K, V], expectedSize int) { + size, err := namedMap.Size(localCtx) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(size).To(gomega.Equal(expectedSize)) +} + +func ClearNamedMap[K comparable, V any](g *gomega.WithT, namedCache coherence.NamedMap[K, V]) { + err := namedCache.Clear(localCtx) + g.Expect(err).NotTo(gomega.HaveOccurred()) +} + +func AssertPersonResult(g *gomega.WithT, result utils.Person, expectedValue utils.Person) { + g.Expect(result).To(gomega.Not(gomega.BeNil())) + g.Expect(result.Name).To(gomega.Equal(expectedValue.Name)) + g.Expect(result.ID).To(gomega.Equal(expectedValue.ID)) +} + +// RunKeyValueTest runs a basic Put/Get test against various key/ values +func RunKeyValueTest[K comparable, V any](g *gomega.WithT, cache coherence.NamedMap[K, V], key K, value V) { + var ( + result *V + err = cache.Clear(localCtx) + oldValue *V + ) + g.Expect(err).NotTo(gomega.HaveOccurred()) + + _, err = cache.Put(localCtx, key, value) + g.Expect(err).NotTo(gomega.HaveOccurred()) + + result, err = cache.Get(localCtx, key) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + + g.Expect(*result).To(gomega.Equal(value)) + + oldValue, err = cache.Remove(localCtx, key) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + g.Expect(oldValue).To(gomega.Equal(result)) +} diff --git a/test/e2e/streaming/streaming_test.go b/test/e2e/streaming/streaming_test.go index f7c7a022..0fc9f26e 100644 --- a/test/e2e/streaming/streaming_test.go +++ b/test/e2e/streaming/streaming_test.go @@ -60,7 +60,7 @@ func TestStreamingConcurrency(t *testing.T) { g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() - cache := utils.GetNamedMap[int, utils.Person](g, session, "streaming-people") + cache := GetNamedMap[int, utils.Person](g, session, "streaming-people") // clear and re-populate g.Expect(cache.Clear(ctx)).ShouldNot(gomega.HaveOccurred()) diff --git a/test/e2e/streaming/suite_test.go b/test/e2e/streaming/suite_test.go index 5fce8fe2..29b3752f 100644 --- a/test/e2e/streaming/suite_test.go +++ b/test/e2e/streaming/suite_test.go @@ -7,11 +7,29 @@ package streaming import ( + "context" + "github.com/onsi/gomega" + "github.com/oracle/coherence-go-client/v2/coherence" "github.com/oracle/coherence-go-client/v2/test/utils" "testing" ) +var localCtx = context.Background() + // The entry point for the test suite func TestMain(m *testing.M) { utils.RunTest(m, 1408, 30000, 8080, true) } + +func GetNamedMapWithScope[K comparable, V any](g *gomega.WithT, session *coherence.Session, cacheName, _ string) coherence.NamedMap[K, V] { + namedCache, err := coherence.GetNamedMap[K, V](session, cacheName) + g.Expect(err).ShouldNot(gomega.HaveOccurred()) + err = namedCache.Clear(localCtx) + g.Expect(err).NotTo(gomega.HaveOccurred()) + + return namedCache +} + +func GetNamedMap[K comparable, V any](g *gomega.WithT, session *coherence.Session, cacheName string) coherence.NamedMap[K, V] { + return GetNamedMapWithScope[K, V](g, session, cacheName, "") +} diff --git a/test/go.mod b/test/go.mod new file mode 100644 index 00000000..658f9250 --- /dev/null +++ b/test/go.mod @@ -0,0 +1,29 @@ +// +// Copyright (c) 2022, 2025 Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at +// https://oss.oracle.com/licenses/upl. +// +module github.com/oracle/coherence-go-client/v2/test + +go 1.23.0 + +toolchain go1.23.7 + +require ( + github.com/google/uuid v1.6.0 + github.com/onsi/gomega v1.37.0 + github.com/oracle/coherence-go-client/v2 v2.3.0 +) + +require ( + github.com/google/go-cmp v0.7.0 // indirect + golang.org/x/net v0.41.0 // indirect + golang.org/x/sys v0.33.0 // indirect + golang.org/x/text v0.26.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a // indirect + google.golang.org/grpc v1.73.0 // indirect + google.golang.org/protobuf v1.36.6 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + +replace github.com/oracle/coherence-go-client/v2 => ../ diff --git a/test/go.sum b/test/go.sum new file mode 100644 index 00000000..b754ff0e --- /dev/null +++ b/test/go.sum @@ -0,0 +1,50 @@ +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= +github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= +github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/onsi/ginkgo/v2 v2.23.3 h1:edHxnszytJ4lD9D5Jjc4tiDkPBZ3siDeJJkUZJJVkp0= +github.com/onsi/ginkgo/v2 v2.23.3/go.mod h1:zXTP6xIp3U8aVuXN8ENK9IXRaTjFnpVB9mGmaSRvxnM= +github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y= +github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ= +go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y= +go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M= +go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE= +go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY= +go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg= +go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o= +go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w= +go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs= +go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= +golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= +golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= +golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= +golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= +golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a h1:v2PbRU4K3llS09c7zodFpNePeamkAwG3mPrAery9VeE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= +google.golang.org/grpc v1.73.0 h1:VIWSmpI2MegBtTuFt5/JWy2oXxtjJ/e89Z70ImfD2ok= +google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7EVBQc= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/test/utils/utils.go b/test/utils/utils.go index 3d4e3bda..cbb0ac57 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -13,7 +13,6 @@ import ( "crypto/x509" "errors" "fmt" - "github.com/onsi/gomega" "github.com/oracle/coherence-go-client/v2/coherence" "io" "log" @@ -119,33 +118,6 @@ func RunTest(m *testing.M, grpcPort, httpPort, restPort int, startup bool) { os.Exit(exitCode) } -// CreateTempDirectory creates a temporary directory -func CreateTempDirectory(pattern string) string { - dir, err := os.MkdirTemp("", pattern) - if err != nil { - fmt.Println("Unable to create temporary directory " + err.Error()) - } - defer os.RemoveAll(dir) - - return dir -} - -// FileExistsInDirectory returns true if a file exists in a directory -func FileExistsInDirectory(dir string, file string) bool { - files, err := os.ReadDir(dir) - - if err != nil { - return false - } - - for _, f := range files { - if f.Name() == file { - return true - } - } - return false -} - // GetFilePath returns the file path of a file func GetFilePath(fileName string) string { _, c, _, _ := runtime.Caller(0) @@ -491,49 +463,6 @@ func validateFilePath(file string) error { return fmt.Errorf("%s is not a valid file", file) } -func GetNamedMapWithScope[K comparable, V any](g *gomega.WithT, session *coherence.Session, cacheName, _ string) coherence.NamedMap[K, V] { - namedCache, err := coherence.GetNamedMap[K, V](session, cacheName) - g.Expect(err).ShouldNot(gomega.HaveOccurred()) - err = namedCache.Clear(localCtx) - g.Expect(err).NotTo(gomega.HaveOccurred()) - - return namedCache -} - -func GetNamedCacheWithScope[K comparable, V any](g *gomega.WithT, session *coherence.Session, cacheName, _ string) coherence.NamedCache[K, V] { - namedCache, err := coherence.GetNamedCache[K, V](session, cacheName) - g.Expect(err).ShouldNot(gomega.HaveOccurred()) - err = namedCache.Clear(localCtx) - g.Expect(err).NotTo(gomega.HaveOccurred()) - - return namedCache -} - -func GetNamedMap[K comparable, V any](g *gomega.WithT, session *coherence.Session, cacheName string) coherence.NamedMap[K, V] { - return GetNamedMapWithScope[K, V](g, session, cacheName, "") -} - -func GetNamedCache[K comparable, V any](g *gomega.WithT, session *coherence.Session, cacheName string) coherence.NamedCache[K, V] { - return GetNamedCacheWithScope[K, V](g, session, cacheName, "") -} - -func AssertSize[K comparable, V any](g *gomega.WithT, namedMap coherence.NamedMap[K, V], expectedSize int) { - size, err := namedMap.Size(localCtx) - g.Expect(err).ShouldNot(gomega.HaveOccurred()) - g.Expect(size).To(gomega.Equal(expectedSize)) -} - -func ClearNamedMap[K comparable, V any](g *gomega.WithT, namedCache coherence.NamedMap[K, V]) { - err := namedCache.Clear(localCtx) - g.Expect(err).NotTo(gomega.HaveOccurred()) -} - -func AssertPersonResult(g *gomega.WithT, result Person, expectedValue Person) { - g.Expect(result).To(gomega.Not(gomega.BeNil())) - g.Expect(result.Name).To(gomega.Equal(expectedValue.Name)) - g.Expect(result.ID).To(gomega.Equal(expectedValue.ID)) -} - type Person struct { ID int `json:"id"` Name string `json:"name"` @@ -567,45 +496,6 @@ type Address struct { PostCode int `json:"postCode"` } -// RunKeyValueTest runs a basic Put/Get test against various key/ values -func RunKeyValueTest[K comparable, V any](g *gomega.WithT, cache coherence.NamedMap[K, V], key K, value V) { - var ( - result *V - err = cache.Clear(localCtx) - oldValue *V - ) - g.Expect(err).NotTo(gomega.HaveOccurred()) - - _, err = cache.Put(localCtx, key, value) - g.Expect(err).NotTo(gomega.HaveOccurred()) - - result, err = cache.Get(localCtx, key) - g.Expect(err).ShouldNot(gomega.HaveOccurred()) - - g.Expect(*result).To(gomega.Equal(value)) - - oldValue, err = cache.Remove(localCtx, key) - g.Expect(err).ShouldNot(gomega.HaveOccurred()) - g.Expect(oldValue).To(gomega.Equal(result)) -} - -// RunKeyValueTestNamedCache runs a basic Put/Get test against various key/ values -func RunKeyValueTestNamedCache[K comparable, V any](g *gomega.WithT, cache coherence.NamedCache[K, V], key K, value V) { - var ( - result interface{} - err = cache.Clear(localCtx) - ) - g.Expect(err).NotTo(gomega.HaveOccurred()) - - _, err = cache.Put(localCtx, key, value) - g.Expect(err).NotTo(gomega.HaveOccurred()) - - result, err = cache.Get(localCtx, key) - g.Expect(err).ShouldNot(gomega.HaveOccurred()) - - g.Expect(result).To(gomega.Equal(value)) -} - // getDockerComposeCommand returns true if we should use "docker-compose" (v1). func useDockerComposeV1() bool { return os.Getenv("DOCKER_COMPOSE_V1") != "" @@ -623,18 +513,3 @@ func getDockerComposeCommand(arguments ...string) (string, []string) { return command, args } - -func RunNSTestWithNamedMap(ctx context.Context, g *gomega.WithT, session *coherence.Session, cache string) { - namedMap, err := coherence.GetNamedMap[string, string](session, cache) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - defer func() { - _ = namedMap.Destroy(ctx) - }() - - _, err = namedMap.Put(ctx, "one", "ONE") - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - - size, err := namedMap.Size(ctx) - g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) - g.Expect(size).To(gomega.Equal(1)) -}