Skip to content

Commit

Permalink
Updated to use the latest central-services-database with a connection… (
Browse files Browse the repository at this point in the history
#157)

* Updated to use the latest central-services-database with a connection object
Updated dependencies and new central-ledger-dependency
Fixed tests

* change password for integration tests as per @ggrg request
  • Loading branch information
rmothilal authored Oct 14, 2019
1 parent 9f83aab commit 0661d27
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 334 deletions.
17 changes: 0 additions & 17 deletions .istanbul.yml

This file was deleted.

5 changes: 1 addition & 4 deletions .ncurc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"reject": [
"@hapi/hapi",
"@hapi/joi"
]
"reject": []
}
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ TBA
## Configuration

Currently the only configuration, necessary is kept [here](./config/default.json)
Example values are as follows:

```json
{
"PORT": 3007,
"HOSTNAME": "http://central-settlements.local",
"DATABASE_URI" : "mysql://central_ledger:password@localhost:3306/central_ledger"
}
```

## Environmental variables

Expand Down
18 changes: 17 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
{
"PORT": 3007,
"HOSTNAME": "http://central-settlements.local",
"DATABASE_URI" : "mysql://central_ledger:password@localhost:3306/central_ledger",
"DATABASE": {
"DIALECT": "mysql",
"HOST": "localhost",
"PORT": 3306,
"USER": "central_ledger",
"PASSWORD": "password",
"SCHEMA": "central_ledger",
"POOL_MIN_SIZE": 10,
"POOL_MAX_SIZE": 10,
"ACQUIRE_TIMEOUT_MILLIS": 30000,
"CREATE_TIMEOUT_MILLIS": 30000,
"DESTROY_TIMEOUT_MILLIS": 5000,
"IDLE_TIMEOUT_MILLIS": 30000,
"REAP_INTERVAL_MILLIS": 1000,
"CREATE_RETRY_INTERVAL_MILLIS": 200,
"DEBUG": false
},
"TRANSFER_VALIDITY_SECONDS": "432000",
"HUB_PARTICIPANT": {
"ID": 1,
Expand Down
18 changes: 17 additions & 1 deletion docker/central-settlement/default.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
{
"PORT": 3007,
"HOSTNAME": "http://central-settlements.local",
"DATABASE_URI": "mysql://central_ledger:password@mysql:3306/central_ledger",
"DATABASE": {
"DIALECT": "mysql",
"HOST": "localhost",
"PORT": 3306,
"USER": "central_ledger",
"PASSWORD": "password",
"SCHEMA": "central_ledger",
"POOL_MIN_SIZE": 10,
"POOL_MAX_SIZE": 10,
"ACQUIRE_TIMEOUT_MILLIS": 30000,
"CREATE_TIMEOUT_MILLIS": 30000,
"DESTROY_TIMEOUT_MILLIS": 5000,
"IDLE_TIMEOUT_MILLIS": 30000,
"REAP_INTERVAL_MILLIS": 1000,
"CREATE_RETRY_INTERVAL_MILLIS": 200,
"DEBUG": false
},
"TRANSFER_VALIDITY_SECONDS": "432000",
"HUB_PARTICIPANT": {
"ID": 1,
Expand Down
432 changes: 149 additions & 283 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "central-settlement",
"description": "Central settlements hosted by a scheme to record and make settlements",
"version": "8.2.0",
"version": "8.3.0",
"license": "Apache-2.0",
"private": false,
"author": "ModusBox",
"contributors": [
"Georgi Georgiev <georgi.georgiev@modusbox.com>",
"Valentin Genev <valentin.genev@modusbox.com>",
"Deon Botha <deon.botha@modusbox.com>",
"Miguel de Barros <miguel.debarros@modusbox.com>"
"Miguel de Barros <miguel.debarros@modusbox.com>",
"Rajiv Mothilal <rajiv.mothilal@modusbox.com>"
],
"repository": {
"type": "git",
Expand All @@ -23,17 +24,17 @@
"@hapi/basic": "5.1.1",
"@hapi/boom": "8.0.1",
"@hapi/catbox-memory": "4.1.1",
"@hapi/good": "8.2.3",
"@hapi/good": "8.2.4",
"@hapi/hapi": "18.4.0",
"@hapi/inert": "5.2.2",
"@hapi/vision": "5.5.4",
"@mojaloop/central-ledger": "8.1.1",
"@mojaloop/central-ledger": "8.2.4",
"@mojaloop/central-services-auth": "5.2.1",
"@mojaloop/central-services-database": "7.4.0",
"@mojaloop/central-services-error-handling": "8.2.0",
"@mojaloop/central-services-database": "8.2.1",
"@mojaloop/central-services-error-handling": "8.2.1",
"@mojaloop/central-services-health": "8.1.1",
"@mojaloop/central-services-logger": "8.1.2",
"@mojaloop/central-services-shared": "8.1.5",
"@mojaloop/central-services-shared": "8.2.0",
"@mojaloop/central-services-stream": "8.1.1",
"@mojaloop/forensic-logging-client": "5.2.0",
"@mojaloop/ml-number": "8.2.0",
Expand All @@ -47,14 +48,14 @@
"uuid4": "1.1.4"
},
"devDependencies": {
"@hapi/joi": "16.1.5",
"@hapi/joi": "16.1.7",
"bluebird": "3.7.0",
"eslint": "6.5.1",
"faucet": "0.0.1",
"node-fetch": "2.6.0",
"nodemon": "1.19.3",
"npm-audit-resolver": "2.0.1",
"npm-check-updates": "3.1.23",
"npm-check-updates": "3.1.24",
"nyc": "14.1.1",
"pre-commit": "1.2.2",
"proxyquire": "2.1.3",
Expand All @@ -74,7 +75,6 @@
"scripts": {
"start": "node src/server.js",
"dev": "nodemon src/server.js",
"pretest": "standard",
"standard": "standard",
"test": "npm run test:unit | faucet",
"test:unit": "tape 'test/unit/**/*.js'",
Expand Down
34 changes: 33 additions & 1 deletion src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,39 @@ const RC = require('rc')('CSET', require('../../config/default.json'))
module.exports = {
HOSTNAME: RC.HOSTNAME.replace(/\/$/, ''),
PORT: RC.PORT,
DATABASE_URI: RC.DATABASE_URI,
DATABASE: {
client: RC.DATABASE.DIALECT,
connection: {
host: RC.DATABASE.HOST.replace(/\/$/, ''),
port: RC.DATABASE.PORT,
user: RC.DATABASE.USER,
password: RC.DATABASE.PASSWORD,
database: RC.DATABASE.SCHEMA
},
pool: {
// minimum size
min: RC.DATABASE.POOL_MIN_SIZE,
// maximum size
max: RC.DATABASE.POOL_MAX_SIZE,
// acquire promises are rejected after this many milliseconds
// if a resource cannot be acquired
acquireTimeoutMillis: RC.DATABASE.ACQUIRE_TIMEOUT_MILLIS,
// create operations are cancelled after this many milliseconds
// if a resource cannot be acquired
createTimeoutMillis: RC.DATABASE.CREATE_TIMEOUT_MILLIS,
// destroy operations are awaited for at most this many milliseconds
// new resources will be created after this timeout
destroyTimeoutMillis: RC.DATABASE.DESTROY_TIMEOUT_MILLIS,
// free resouces are destroyed after this many milliseconds
idleTimeoutMillis: RC.DATABASE.IDLE_TIMEOUT_MILLIS,
// how often to check for idle resources to destroy
reapIntervalMillis: RC.DATABASE.REAP_INTERVAL_MILLIS,
// long long to idle after failed create before trying again
createRetryIntervalMillis: RC.DATABASE.CREATE_RETRY_INTERVAL_MILLIS
// ping: function (conn, cb) { conn.query('SELECT 1', cb) }
},
debug: RC.DATABASE.DEBUG
},
TRANSFER_VALIDITY_SECONDS: RC.TRANSFER_VALIDITY_SECONDS,
HUB_ID: RC.HUB_PARTICIPANT.ID,
HUB_NAME: RC.HUB_PARTICIPANT.NAME,
Expand Down
3 changes: 1 addition & 2 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ const getEnums = (id) => {
}

async function connectDatabase () {
const db = await Db.connect(Config.DATABASE_URI)
return db
return Db.connect(Config.DATABASE)
}

const createServer = async function (config, openAPIPluginOptions) {
Expand Down
17 changes: 17 additions & 0 deletions test/integration-config-centralledger.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
{
"PORT": 3001,
"HOSTNAME": "http://central-ledger",
"DATABASE": {
"DIALECT": "mysql",
"HOST": "db-int",
"PORT": 3306,
"USER": "central_ledger",
"PASSWORD": "password",
"SCHEMA": "central_ledger_integration",
"POOL_MIN_SIZE": 10,
"POOL_MAX_SIZE": 10,
"ACQUIRE_TIMEOUT_MILLIS": 30000,
"CREATE_TIMEOUT_MILLIS": 30000,
"DESTROY_TIMEOUT_MILLIS": 5000,
"IDLE_TIMEOUT_MILLIS": 30000,
"REAP_INTERVAL_MILLIS": 1000,
"CREATE_RETRY_INTERVAL_MILLIS": 200,
"DEBUG": false
},
"MIGRATIONS": {
"DISABLED": false,
"RUN_DATA_MIGRATIONS": true
Expand Down
18 changes: 17 additions & 1 deletion test/integration-config-centralsettlement.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
{
"PORT": 3007,
"HOSTNAME": "http://central-settlements.local",
"DATABASE_URI" : "mysql://central_ledger:cVq8iFqaLuHy8jjKuA@db-int:3306/central_ledger_integration",
"DATABASE": {
"DIALECT": "mysql",
"HOST": "db-int",
"PORT": 3306,
"USER": "central_ledger",
"PASSWORD": "password",
"SCHEMA": "central_ledger_integration",
"POOL_MIN_SIZE": 10,
"POOL_MAX_SIZE": 10,
"ACQUIRE_TIMEOUT_MILLIS": 30000,
"CREATE_TIMEOUT_MILLIS": 30000,
"DESTROY_TIMEOUT_MILLIS": 5000,
"IDLE_TIMEOUT_MILLIS": 30000,
"REAP_INTERVAL_MILLIS": 1000,
"CREATE_RETRY_INTERVAL_MILLIS": 200,
"DEBUG": false
},
"TRANSFER_VALIDITY_SECONDS": "432000",
"HUB_PARTICIPANT": {
"ID": 1,
Expand Down
2 changes: 1 addition & 1 deletion test/integration-runner.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DOCKER_WORKING_DIR=${DOCKER_WORKING_DIR:-"/opt/central-settlement"}
DOCKER_NETWORK=${DOCKER_NETWORK:-"integration-test-net"}

DB_USER=${DB_USER:-"central_ledger"}
DB_PASSWORD=${DB_PASSWORD:-"cVq8iFqaLuHy8jjKuA"}
DB_PASSWORD=${DB_PASSWORD:-"password"}
DB_HOST=${DB_HOST:-"db-int"}
DB_PORT=${DB_PORT:-3306}
DB_NAME=${DB_NAME:-"central_ledger_integration"}
Expand Down
3 changes: 1 addition & 2 deletions test/integration-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fcmd_centralledger() {
--link $DB_HOST \
--network $DOCKER_NETWORK \
--env HOST_IP="$APP_HOST" \
--env CLEDG_DATABASE_URI="mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}" \
--volume ${PWD}/test/integration-config-centralledger.json:/opt/central-ledger/config/default.json \
$CENTRAL_LEDGER_IMAGE:$CENTRAL_LEDGER_TAG \
/bin/sh \
-c "$@"
Expand Down Expand Up @@ -216,7 +216,6 @@ start_central_ledger () {
--network $DOCKER_NETWORK \
--name=$CENTRAL_LEDGER_HOST \
--volume ${PWD}/test/integration-config-centralledger.json:/opt/central-ledger/config/default.json \
--env CLEDG_DATABASE_URI="mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}" \
$CENTRAL_LEDGER_IMAGE:$CENTRAL_LEDGER_TAG
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/handlers/health.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const healthHandler = require('../../../src/handlers/health')
Test('Health Handler', async handlersTest => {
await handlersTest.test('registerAllHandlers should', async registerAllHandlers => {
await registerAllHandlers.test('setup handlers', async (test) => {
await Db.connect(Config.DATABASE_URI)
await Db.connect(Config.DATABASE)

test.pass('done')
test.end()
Expand Down
2 changes: 1 addition & 1 deletion test/integration/settlementTransfer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const getEnums = async () => {
PrepareTransferData()

Test('SettlementTransfer should', async settlementTransferTest => {
await Db.connect(Config.DATABASE_URI)
await Db.connect(Config.DATABASE)
const enums = await getEnums()
let settlementWindowId
let settlementData
Expand Down

0 comments on commit 0661d27

Please sign in to comment.