Skip to content

Commit

Permalink
- Change format of coherence url
Browse files Browse the repository at this point in the history
  • Loading branch information
rlubke committed Feb 4, 2025
1 parent 9fde482 commit 69f7010
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ let session = new Session(opts)

As of v1.2.3 of the JavaScript Client for Oracle Coherence, it's now possible to use the Coherence
NameService to lookup gRPC Proxy endpoints. The format to enable this feature is
`coherence:///<host>([:port]|[:cluster-name]|[:port:cluster-name])`
`coherence:///<host>([:port]|[/cluster-name]|[:port/cluster-name])`

For example:
* `coherence:///localhost` will connect to the name service bound to a local coherence cluster on port `7574` (the default Coherence cluster port).
* `coherence:///localhost:8000` will connect to the name service bound to a local coherence cluster on port `8000`.
* `coherence:///localhost:remote-cluster` will connect to the name service bound to a local coherence cluster on port `7574` (the default Coherence cluster port) and look up the name service for the given cluster name. Note: this typically means both clusters have a local member sharing a cluster port.
* `coherence:///localhost:8000:remote-cluster` will connect to the name service bound to a local coherence cluster on port `8000` and look up the name service for the given cluster name. Note: this typically means both clusters have a local member sharing a cluster port.
* `coherence:///localhost/remote-cluster` will connect to the name service bound to a local coherence cluster on port `7574` (the default Coherence cluster port) and look up the name service for the given cluster name. Note: this typically means both clusters have a local member sharing a cluster port.
* `coherence:///localhost:8000/remote-cluster` will connect to the name service bound to a local coherence cluster on port `8000` and look up the name service for the given cluster name. Note: this typically means both clusters have a local member sharing a cluster port.

While this is useful for local development, this may have limited uses in a production environment. For example,
Coherence running within a container with the cluster port (`7574`) exposed so external clients may connect. The
Expand All @@ -146,7 +146,7 @@ a custom channel option when creating the session:
```typescript
const { Session } = require('@oracle/coherence')

const opts = new Options({address: 'example.com:4444',
const opts = new Options({address: 'coherence:///localhost',
channelOptions: {'grpc.service_config': JSON.stringify({ loadBalancingConfig: [{ round_robin: {} }], })}})

let session = new Session(opts)
Expand Down
10 changes: 5 additions & 5 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Options {
/**
* Regular expression for basic validation of IPv4 address.
*/
private static readonly ADDRESS_REGEXP = RegExp('^(coherence:\/\/\/\\S+|coherence:\\S+:\\d{1,5}|coherence:\/\/\/\\S+:\\d{1,5}:[a-zA-Z0-9]+|coherence:\/\/\/\\S+:[a-zA-Z0-9]+|\\S+:\\d{1,5})$')
private static readonly ADDRESS_REGEXP = RegExp('^(coherence:///\\S+|coherence:\\S+:\\d{1,5}|coherence:///\\S+:\\d{1,5}/[a-zA-Z0-9]+|coherence:///\\S+/[a-zA-Z0-9]+|\\S+:\\d{1,5})$')

/**
* Address of the target Coherence cluster. If not explicitly set, this defaults to {@link Session.DEFAULT_ADDRESS}.
Expand Down Expand Up @@ -107,19 +107,19 @@ export class Options {
* If the Coherence cluster port is available, it's possible to uss
* the Coherence name service in order to resolve and connect to the available
* gRPC proxies. If using this functionality, the format is
* `coherence:///<host>([:port]|[:cluster-name]|[:port:cluster-name])`.
* `coherence:///<host>([:port]|[/cluster-name]|[:port/cluster-name])`.
*
* @param address the IPv4 host address and port in the format of `[host]:[port]`
* or the Coherence name service format of
* `coherence:///<host>([:port]|[:cluster-name]|[:port:cluster-name])`
* `coherence:///<host>([:port]|[/cluster-name]|[:port/cluster-name])`
*/
set address (address: string) {
if (this.locked) {
return
}
// ensure address is sane
if (!Options.ADDRESS_REGEXP.test(address)) {
throw new Error('Expected address format is \'<hostname>:<port>\' or \'coherence:<host>([:port]|[:cluster-name]|[:port:cluster-name])\'. Configured: ' + address)
throw new Error('Expected address format is \'<hostname>:<port>\' or \'coherence:<host>([:port]|[/cluster-name]|[:port/cluster-name])\'. Configured: ' + address)
}

this._address = address
Expand Down Expand Up @@ -986,7 +986,7 @@ export class CoherenceResolver implements experimental.Resolver {
}

static parseConn(path: string): [string, string, string] {
let parts: string[] = path.split(':')
let parts: string[] = path.split(/[/:]/)
const host = parts[0]
let port = '7574'
let clusterName = ''
Expand Down
6 changes: 3 additions & 3 deletions test/discovery/resolver-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ describe('CoherenceResolver Test Suite (unit/IT)', () => {
})

it('should parse and resolve the connection format \'coherence:///[host]:[clusterName]\'', (done) => {
const resolver = new CoherenceResolver({scheme: 'coherence', path: 'localhost:grpc-cluster2'}, createListener(done, 10001), null)
const resolver = new CoherenceResolver({scheme: 'coherence', path: 'localhost/grpc-cluster2'}, createListener(done, 10001), null)
resolver.updateResolution()
})

it('should parse and resolve the connection format \'coherence:///[host]:[port]:[clusterName]\'', (done) => {
const resolver = new CoherenceResolver({scheme: 'coherence', path: 'localhost:7574:grpc-cluster2'}, createListener(done, 10001), null)
const resolver = new CoherenceResolver({scheme: 'coherence', path: 'localhost:7574/grpc-cluster2'}, createListener(done, 10001), null)
resolver.updateResolution()
})
})
Expand All @@ -67,7 +67,7 @@ describe('CoherenceResolver Test Suite (unit/IT)', () => {
})

it('should be able to resolve the gRPC Proxy of a foreign cluster', async () => {
const session = new Session({address: 'coherence:///localhost:grpc-cluster2'})
const session = new Session({address: 'coherence:///localhost/grpc-cluster2'})
const cache = session.getCache('test')
await cache.set('a', 'b')
assert.equal(await cache.get('a'), 'b')
Expand Down

0 comments on commit 69f7010

Please sign in to comment.