Skip to content

Commit 95c4d31

Browse files
author
Tim Middleton
authored
Update CI/CD badge (#306)
* Update CI/CD badge * Add event listeners to starter projects * Test updates
1 parent 55ab8ab commit 95c4d31

File tree

6 files changed

+158
-14
lines changed

6 files changed

+158
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ https://oss.oracle.com/licenses/upl.
77
-----
88
![logo](docs/images/logo-with-name.png)
99

10-
![Coherence CI](https://github.com/oracle/coherence-cli/workflows/CI/badge.svg?branch=main)
10+
![Coherence CI](https://github.com/oracle/coherence-cli/actions/workflows/build.yaml/badge.svg?branch=main)
1111
[![License](http://img.shields.io/badge/license-UPL%201.0-blue.svg)](https://oss.oracle.com/licenses/upl/)
1212

1313
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=oracle_coherence-cli&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=oracle_coherence-cli)

pkg/cmd/starter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Get all customers:
4949
5050
Delete a customer:
5151
curl -X DELETE http://localhost:8080/api/customers/1
52+
53+
Note: you will see log messages shown for registered event listeners for insert, update and delete events.
5254
`
5355
)
5456

templates/helidon/src/main/java/com/oracle/coherence/demo/frameworks/helidon/CustomerResource.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
1010

11+
import com.oracle.coherence.cdi.WhereFilter;
12+
import com.oracle.coherence.cdi.events.*;
13+
import com.oracle.coherence.common.base.Logger;
1114
import com.tangosol.net.NamedMap;
1215

16+
import com.tangosol.util.MapEvent;
1317
import jakarta.enterprise.context.ApplicationScoped;
18+
import jakarta.enterprise.event.Observes;
1419
import jakarta.inject.Inject;
1520

1621
import jakarta.ws.rs.Consumes;
1722
import jakarta.ws.rs.DELETE;
1823
import jakarta.ws.rs.GET;
1924
import jakarta.ws.rs.POST;
20-
2125
import jakarta.ws.rs.Path;
2226
import jakarta.ws.rs.PathParam;
2327
import jakarta.ws.rs.Produces;
@@ -59,4 +63,39 @@ public Response deleteTask(@PathParam("id") int id) {
5963
Customer oldCustomer = customers.remove(id);
6064
return oldCustomer == null ? Response.status(Response.Status.NOT_FOUND).build() : Response.ok(oldCustomer).build();
6165
}
66+
67+
// --- Register Map Listeners
68+
69+
/**
70+
* Event fired on inserting of a {@link Customer}.
71+
* @param event event information
72+
*/
73+
private void onCustomerInserted(@Observes @Inserted @MapName("customers") MapEvent<Integer, Customer> event) {
74+
Logger.info("Customer Inserted: id=" + event.getKey() + ", value=" + event.getNewValue());
75+
}
76+
77+
/**
78+
* Event fired on updating of a {@link Customer}.
79+
* @param event event information
80+
*/
81+
private void onCustomerUpdated(@Observes @Updated @MapName("customers") MapEvent<Integer, Customer> event) {
82+
Logger.info("Customer Updated: id=" + event.getKey() + ", new value=" + event.getNewValue() + ", old value=" + event.getOldValue());
83+
}
84+
85+
/**
86+
* Event fired on deletion a {@link Customer}.
87+
* @param event event information
88+
*/
89+
private void onCustomerDeleted(@Observes @Deleted @MapName("customers") MapEvent<Integer, Customer> event) {
90+
Logger.info("Customer Deleted: id=" + event.getKey() + ", old value=" + event.getOldValue());
91+
}
92+
93+
/**
94+
* Event fired on deleting of a {@link Customer} when they have a large balance > 5000.
95+
* @param event event information
96+
*/
97+
@WhereFilter("balance > 5000.0d")
98+
private void onCustomerDeletedLargeBalance(@Observes @Deleted @MapName("customers") MapEvent<Integer, Customer> event) {
99+
Logger.info("Customer Updated: (Large Balance) id=" + event.getKey() + ", old value=" + event.getOldValue());
100+
}
62101
}

templates/micronaut/src/main/java/com/oracle/coherence/demo/frameworks/micronaut/rest/ApplicationController.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@
88
package com.oracle.coherence.demo.frameworks.micronaut.rest;
99

1010
import java.util.Collection;
11+
12+
import com.oracle.coherence.common.base.Logger;
13+
1114
import com.oracle.coherence.demo.frameworks.micronaut.Customer;
1215

1316
import com.tangosol.net.NamedCache;
1417

18+
import com.tangosol.util.MapEvent;
19+
20+
import io.micronaut.coherence.annotation.*;
21+
1522
import io.micronaut.http.HttpResponse;
1623
import io.micronaut.http.MediaType;
24+
1725
import io.micronaut.http.annotation.Body;
1826
import io.micronaut.http.annotation.Controller;
19-
2027
import io.micronaut.http.annotation.Delete;
2128
import io.micronaut.http.annotation.Get;
2229
import io.micronaut.http.annotation.PathVariable;
@@ -54,4 +61,43 @@ public HttpResponse<Customer> deleteCustomer(@PathVariable("id") int id) {
5461
Customer oldCustomer = customers.remove(id);
5562
return oldCustomer == null ? HttpResponse.notFound() : HttpResponse.accepted();
5663
}
64+
65+
// --- Register Map Listeners
66+
67+
/**
68+
* Event fired on inserting of a {@link Customer}.
69+
* @param event event information
70+
*/
71+
@CoherenceEventListener
72+
public void onCustomerInserted(@Inserted @MapName("customers") MapEvent<Integer, Customer> event) {
73+
Logger.info("Customer Inserted: id=" + event.getKey() + ", value=" + event.getNewValue());
74+
}
75+
76+
/**
77+
* Event fired on updating of a {@link Customer}.
78+
* @param event event information
79+
*/
80+
@CoherenceEventListener
81+
public void onCustomerUpdated(@Updated @MapName("customers") MapEvent<Integer, Customer> event) {
82+
Logger.info("Customer Updated: id=" + event.getKey() + ", new value=" + event.getNewValue() + ", old value=" + event.getOldValue());
83+
}
84+
85+
/**
86+
* Event fired on deletion a {@link Customer}.
87+
* @param event event information
88+
*/
89+
@CoherenceEventListener
90+
public void onCustomerDeleted(@Deleted @MapName("customers") MapEvent<Integer, Customer> event) {
91+
Logger.info("Customer Deleted: id=" + event.getKey() + ", old value=" + event.getOldValue());
92+
}
93+
94+
/**
95+
* Event fired on deleting of a {@link Customer} when they have a large balance > 5000.
96+
* @param event event information
97+
*/
98+
@CoherenceEventListener
99+
@WhereFilter("balance > 5000.0d")
100+
public void onCustomerDeletedLargeBalance(@Deleted @MapName("customers") MapEvent<Integer, Customer> event) {
101+
Logger.info("Customer Updated: (Large Balance) id=" + event.getKey() + ", old value=" + event.getOldValue());
102+
}
57103
}

templates/springboot/src/main/java/com/oracle/coherence/demo/frameworks/springboot/controller/DemoController.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,29 @@
66

77
package com.oracle.coherence.demo.frameworks.springboot.controller;
88

9+
import com.oracle.coherence.common.base.Logger;
10+
911
import com.oracle.coherence.demo.frameworks.springboot.Customer;
12+
13+
import com.oracle.coherence.spring.annotation.WhereFilter;
14+
import com.oracle.coherence.spring.annotation.event.Deleted;
15+
import com.oracle.coherence.spring.annotation.event.Inserted;
16+
import com.oracle.coherence.spring.annotation.event.MapName;
17+
import com.oracle.coherence.spring.annotation.event.Updated;
1018
import com.oracle.coherence.spring.configuration.annotation.CoherenceCache;
1119

20+
import com.oracle.coherence.spring.event.CoherenceEventListener;
21+
1222
import com.tangosol.net.NamedCache;
1323

24+
import com.tangosol.util.MapEvent;
1425
import org.springframework.http.ResponseEntity;
1526
import org.springframework.web.bind.annotation.DeleteMapping;
1627
import org.springframework.web.bind.annotation.GetMapping;
1728
import org.springframework.web.bind.annotation.PathVariable;
1829
import org.springframework.web.bind.annotation.PostMapping;
1930
import org.springframework.web.bind.annotation.RequestBody;
2031
import org.springframework.web.bind.annotation.RequestMapping;
21-
import org.springframework.web.bind.annotation.RequestParam;
2232
import org.springframework.web.bind.annotation.RestController;
2333

2434
import java.util.Collection;
@@ -55,4 +65,42 @@ public void removeCustomer(@PathVariable int id) {
5565
customers.remove(id);
5666
}
5767

68+
// --- Register Map Listeners
69+
70+
/**
71+
* Event fired on inserting of a {@link Customer}.
72+
* @param event event information
73+
*/
74+
@CoherenceEventListener
75+
private void onCustomerInserted(@Inserted @MapName("customers") MapEvent<Integer, Customer> event) {
76+
Logger.info("Customer Inserted: id=" + event.getKey() + ", value=" + event.getNewValue());
77+
}
78+
79+
/**
80+
* Event fired on updating of a {@link Customer}.
81+
* @param event event information
82+
*/
83+
@CoherenceEventListener
84+
private void onCustomerUpdated(@Updated @MapName("customers") MapEvent<Integer, Customer> event) {
85+
Logger.info("Customer Updated: id=" + event.getKey() + ", new value=" + event.getNewValue() + ", old value=" + event.getOldValue());
86+
}
87+
88+
/**
89+
* Event fired on deletion a {@link Customer}.
90+
* @param event event information
91+
*/
92+
@CoherenceEventListener
93+
private void onCustomerDeleted(@Deleted @MapName("customers") MapEvent<Integer, Customer> event) {
94+
Logger.info("Customer Deleted: id=" + event.getKey() + ", old value=" + event.getOldValue());
95+
}
96+
97+
/**
98+
* Event fired on deleting of a {@link Customer} when they have a large balance > 5000.
99+
* @param event event information
100+
*/
101+
@CoherenceEventListener
102+
@WhereFilter("balance > 5000.0d")
103+
private void onCustomerDeletedLargeBalance(@Deleted @MapName("customers") MapEvent<Integer, Customer> event) {
104+
Logger.info("Customer Updated: (Large Balance) id=" + event.getKey() + ", old value=" + event.getOldValue());
105+
}
58106
}

test/common/common.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
const (
2626
configArg = "--config"
2727
addedCluster = "Added cluster"
28-
version1221 = "12.2.1"
29-
version1411 = "14.1.1"
28+
version1221 = "12.2.1.4"
29+
version1411 = "14.1.1.1"
3030
configYaml = "config.yaml"
3131
nodeID = "NODE ID"
3232
jsonPathServices = "jsonpath=$.services"
@@ -40,8 +40,14 @@ const (
4040

4141
// RunTestClusterCommands tests add/remove/get/describe cluster commands.
4242
func RunTestClusterCommands(t *testing.T) {
43-
context := test_utils.GetTestContext()
44-
g := NewGomegaWithT(t)
43+
var (
44+
context = test_utils.GetTestContext()
45+
restUrl = context.RestUrl
46+
g = NewGomegaWithT(t)
47+
)
48+
49+
versionString, err := getVersion(restUrl)
50+
g.Expect(err).To(BeNil())
4551

4652
file := initializeTestFile(t)
4753
cliCmd := cmd.Initialize(nil)
@@ -144,14 +150,17 @@ func RunTestClusterCommands(t *testing.T) {
144150
test_utils.EnsureCommandErrorContains(g, t, cliCmd, "invalid value for loggingLevel", configArg, file,
145151
"set", "cluster", "cluster1", "-a", "loggingLevel", "-v", "XYZ", "-y")
146152

147-
// test set the logging level to 8
148-
test_utils.EnsureCommandContainsAll(g, t, cliCmd, cmd.OperationCompleted, configArg, file,
149-
"set", "cluster", "cluster1", "-a", "loggingLevel", "-v", "8", "-y")
153+
// only skip test for 14.1.1.0 and 12.2.1.4
154+
if !strings.Contains(versionString, version1221) && !strings.Contains(versionString, version1411) {
155+
// test set the logging level to 8
156+
test_utils.EnsureCommandContainsAll(g, t, cliCmd, cmd.OperationCompleted, configArg, file,
157+
"set", "cluster", "cluster1", "-a", "loggingLevel", "-v", "8", "-y")
150158

151-
test_utils.Sleep(15)
159+
test_utils.Sleep(15)
152160

153-
// validate the value was set
154-
test_utils.EnsureCommandContains(g, t, cliCmd, "\"loggingLevel\":8", configArg, file, "get", "members", "-o", "json", "-c", context.ClusterName)
161+
// validate the value was set
162+
test_utils.EnsureCommandContains(g, t, cliCmd, "\"loggingLevel\":8", configArg, file, "get", "members", "-o", "json", "-c", context.ClusterName)
163+
}
155164

156165
// remove the cluster entries
157166
test_utils.EnsureCommandContains(g, t, cliCmd, context.ClusterName, configArg, file, "remove", "cluster", "cluster1")

0 commit comments

Comments
 (0)