Skip to content

Commit 3615c9d

Browse files
authored
Add test cases for extend client inside kubernetes cluster (#503)
1 parent 6250930 commit 3615c9d

File tree

7 files changed

+87
-8
lines changed

7 files changed

+87
-8
lines changed

api/v1/coherenceresourcespec_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ func (in *CoherenceResourceSpec) FindPortServiceNames(deployment *Coherence) map
501501
m[port.Name] = s
502502
}
503503
}
504+
505+
// manually add the wka port which will be <resource-name>-wka
506+
m["wka"] = deployment.Name + "-wka"
504507
}
505508
return m
506509
}

controllers/statefulset/probe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func (in *CoherenceProbe) ProbeUsingHTTP(pod corev1.Pod, handler *coh.Probe) (bo
273273
p := httpprobe.New()
274274
result, s, err := p.Probe(u, header, handler.GetTimeout())
275275

276-
log.Info(fmt.Sprintf("HTTP Probe URL: %s result=%s msg=%s error=%s", u.String(), result, s, err))
276+
log.Info(fmt.Sprintf("HTTP Probe URL: %s result=%v msg=%s error=%s", u.String(), result, s, err))
277277

278278
return result == probe.Success, err
279279
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Copyright (c) 2021, Oracle and/or its affiliates.
4+
~ Licensed under the Universal Permissive License v 1.0 as shown at
5+
~ http://oss.oracle.com/licenses/upl.
6+
-->
7+
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
9+
xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">
10+
11+
<caching-scheme-mapping>
12+
<cache-mapping>
13+
<cache-name>*</cache-name>
14+
<scheme-name>remote-scheme</scheme-name>
15+
</cache-mapping>
16+
</caching-scheme-mapping>
17+
18+
<caching-schemes>
19+
<remote-cache-scheme>
20+
<scheme-name>remote-scheme</scheme-name>
21+
<service-name>RemoteCache</service-name>
22+
<proxy-service-name>Proxy</proxy-service-name>
23+
<initiator-config>
24+
<tcp-initiator>
25+
<name-service-addresses>
26+
<socket-address>
27+
<address system-property="coherence.extend.address">127.0.0.1</address>
28+
<port system-property="coherence.extend.port">20000</port>
29+
</socket-address>
30+
</name-service-addresses>
31+
</tcp-initiator>
32+
</initiator-config>
33+
</remote-cache-scheme>
34+
</caching-schemes>
35+
</cache-config>

java/operator-test-client/src/main/resources/test-cache-config.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
-->
77
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
88
xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
9-
xmlns:xi="http://www.w3.org/2001/XInclude"
109
xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">
1110

1211
<caching-scheme-mapping>
@@ -17,7 +16,6 @@
1716
</caching-scheme-mapping>
1817

1918
<caching-schemes>
20-
<xi:include href="remote-scheme.xml" parse="xml"/>
2119
<remote-cache-scheme>
2220
<scheme-name>remote-scheme</scheme-name>
2321
<service-name>RemoteCache</service-name>

test/e2e/clients/client_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ func TestSimpleClients(t *testing.T) {
2626

2727
// Create all the child test cases.
2828
testCases := []ClientTestCase{
29-
// Simple Extend test
30-
{ClientType: ClientTypeExtend, Name: "ExtendInternal", Cluster: cluster, Test: simpleClientTest},
29+
// Simple Extend test direct connection
30+
{ClientType: ClientTypeExtend, Name: "ExtendInternalDirect", Cluster: cluster, Test: simpleClientTest},
31+
//Simple Extend test name-service connection
32+
{ClientType: ClientTypeExtend, Name: "ExtendInternalNS", Cluster: cluster, Test: simpleClientTest, CacheConfig: "test-cache-config-ns.xml"},
3133
// Simple gRPC test
3234
{ClientType: ClientTypeGrpc, Name: "GrpcInternal", Cluster: cluster, Test: simpleClientTest},
3335
}
@@ -54,11 +56,11 @@ func simpleClientTest(t *testing.T, tc ClientTestCase) {
5456

5557
// ensure we delete the Job when the test finishes
5658
t.Cleanup(func() {
57-
_ = client.Delete(testContext.Context, jobName, metav1.DeleteOptions{})
59+
_ = helper.DeleteJob(testContext, ns, jobName)
5860
})
5961

6062
// ensure there is no Job left from a previous test
61-
_ = client.Delete(testContext.Context, jobName, metav1.DeleteOptions{})
63+
_ = helper.DeleteJob(testContext, ns, jobName)
6264

6365
// Create the Job to run the client
6466
job := CreateClientJob(ns, jobName, tc)

test/e2e/clients/client_test_helpers.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package clients
88

99
import (
10+
v1 "github.com/oracle/coherence-operator/api/v1"
1011
"github.com/oracle/coherence-operator/test/e2e/helper"
1112
batchv1 "k8s.io/api/batch/v1"
1213
corev1 "k8s.io/api/core/v1"
@@ -21,6 +22,7 @@ type CoherenceCluster struct {
2122
Services map[string]string
2223
ServiceFQDNs map[string]string
2324
ServiceIngress map[string][]corev1.LoadBalancerIngress
25+
Coherence v1.Coherence
2426
}
2527

2628
func DeployTestCluster(testContext helper.TestContext, t *testing.T, yaml string) (*CoherenceCluster, error) {
@@ -49,6 +51,7 @@ func DeployTestCluster(testContext helper.TestContext, t *testing.T, yaml string
4951
Services: svcNames,
5052
ServiceFQDNs: svcFQDN,
5153
ServiceIngress: ingress,
54+
Coherence: cluster,
5255
}, nil
5356
}
5457

@@ -74,13 +77,34 @@ func CreateClientJob(ns, name string, tc ClientTestCase) *batchv1.Job {
7477
Name: "COHERENCE_DISTRIBUTED_LOCALSTORAGE",
7578
Value: "false",
7679
},
80+
{
81+
Name: "COHERENCE_CLUSTER",
82+
Value: tc.Cluster.Coherence.GetCoherenceClusterName(),
83+
},
7784
}
7885

7986
switch tc.ClientType {
8087
case ClientTypeExtend:
88+
var extendAddress string
89+
var extendPort string
90+
91+
if tc.Name == "ExtendInternalNS" {
92+
// Use name service
93+
extendAddress = tc.Cluster.ServiceFQDNs["wka"]
94+
extendPort = "7574"
95+
} else {
96+
// use direct socket address
97+
extendAddress = tc.Cluster.ServiceFQDNs["extend"]
98+
extendPort = "20000"
99+
}
100+
81101
envVars = append(envVars, corev1.EnvVar{
82102
Name: "COHERENCE_EXTEND_ADDRESS",
83-
Value: tc.Cluster.ServiceFQDNs["extend"],
103+
Value: extendAddress,
104+
})
105+
envVars = append(envVars, corev1.EnvVar{
106+
Name: "COHERENCE_EXTEND_PORT",
107+
Value: extendPort,
84108
})
85109
case ClientTypeGrpc:
86110
envVars = append(envVars, corev1.EnvVar{

test/e2e/helper/e2e-helpers.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,23 @@ func WaitForOperatorPods(ctx TestContext, namespace string, retryInterval, timeo
497497
return WaitForPodsWithSelector(ctx, namespace, operatorPodSelector, retryInterval, timeout)
498498
}
499499

500+
func DeleteJob(ctx TestContext, namespace, jobName string) error {
501+
client := ctx.KubeClient.BatchV1().Jobs(namespace)
502+
if err := client.Delete(ctx.Context, jobName, metav1.DeleteOptions{}); err != nil && !errors.IsNotFound(err) {
503+
return err
504+
}
505+
pods, err := ListPodsWithLabelSelector(ctx, namespace, "job-name=" + jobName)
506+
if err != nil {
507+
return err
508+
}
509+
510+
for i := range pods {
511+
_ = ctx.Client.Delete(ctx.Context, &pods[i])
512+
}
513+
514+
return nil
515+
}
516+
500517
// WaitForPodsWithSelector waits for a Coherence Operator Pods to be created.
501518
func WaitForPodsWithSelector(ctx TestContext, namespace, selector string, retryInterval, timeout time.Duration) ([]corev1.Pod, error) {
502519
var pods []corev1.Pod

0 commit comments

Comments
 (0)