Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -404,43 +404,43 @@ 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%'

# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go streaming tests for standalone Coherence
# ----------------------------------------------------------------------------------------------------------------------
.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%'

# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go end to end tests for standalone Coherence with Queues
# ----------------------------------------------------------------------------------------------------------------------
.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%'

# ----------------------------------------------------------------------------------------------------------------------
# Executes the Go end to end tests for gRPC v1 tests
# ----------------------------------------------------------------------------------------------------------------------
.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%'

# ----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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

# ----------------------------------------------------------------------------------------------------------------------
Expand All @@ -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/*

Expand All @@ -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
Expand All @@ -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

# ----------------------------------------------------------------------------------------------------------------------
Expand Down
42 changes: 31 additions & 11 deletions coherence/coherence_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
43 changes: 27 additions & 16 deletions coherence/discovery/nslookup_test.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
/*
* 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.
*/

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)
}
}
Loading