Skip to content

Commit 134149f

Browse files
authored
Merge pull request #2 from sharathkumaranbu/tests
Tests and Dockerization
2 parents 5743c76 + f0bd144 commit 134149f

20 files changed

+3435
-351
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
.env
3+
coverage/
4+
.nyc_output/

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ node_modules
33
*.log
44
.DS_Store
55
.env
6+
coverage
7+
.nyc_output

README.md

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
- ElasticSearch
88
- Docker, Docker Compose
99

10-
## Notes
11-
12-
In Elasticsearch v6+, it can support one type per index, see
13-
https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html
14-
so for all 4 types, same configured index type is used, types are distinguished by the 'resource' attribute of indexed data.
15-
1610
## Configuration
1711

1812
Configuration for the notification server is at `config/default.js`.
@@ -29,11 +23,8 @@ The following parameters can be set in config files or in env variables:
2923
- CREATE_DATA_TOPIC: create data Kafka topic, default value is 'submission.notification.create'
3024
- UPDATE_DATA_TOPIC: update data Kafka topic, default value is 'submission.notification.update'
3125
- DELETE_DATA_TOPIC: delete data Kafka topic, default value is 'submission.notification.delete'
32-
- ELASTICSEARCH_CONFIG: the config to create Elasticsearch client, see
33-
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/configuration.html
34-
for full details, SSL connection can be configured in ssl config field
35-
- ELASTICSEARCH_INDEX: the Elasticsearch index to store Kafka messages data, default value is 'submission-index'
36-
- ELASTICSEARCH_INDEX_TYPE: the Elasticsearch index type name, default value is 'submission'
26+
27+
Refer to `esConfig` variable in `config/default.js` for ES related configuration.
3728

3829
Also note that there is a `/health` endpoint that checks for the health of the app. This sets up an expressjs server and listens on the environment variable `PORT`. It's not part of the configuration file and needs to be passed as an environment variable
3930

@@ -64,10 +55,6 @@ Also note that there is a `/health` endpoint that checks for the health of the a
6455
`bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic submission.notification.create --from-beginning`
6556
- writing/reading messages to/from other topics are similar
6657

67-
## ElasticSearch setup
68-
69-
- go to docker folder, run `docker-compose up`
70-
7158
## Local deployment
7259

7360
- install dependencies `npm i`
@@ -77,6 +64,63 @@ Also note that there is a `/health` endpoint that checks for the health of the a
7764
- run tests `npm run test`
7865
- start processor app `npm start`
7966

67+
## Local Deployment with Docker
68+
69+
To run the Submission ES Processor using docker, follow the below steps
70+
71+
1. Navigate to the directory `docker`
72+
73+
2. Rename the file `sample.api.env` to `api.env`
74+
75+
3. Set the required AWS credentials in the file `api.env`
76+
77+
4. Once that is done, run the following command
78+
79+
```
80+
docker-compose up
81+
```
82+
83+
5. When you are running the application for the first time, It will take some time initially to download the image and install the dependencies
84+
85+
## Unit tests and Integration tests
86+
87+
Integration tests use different index `submission-test` which is not same as the usual index `submission`.
88+
89+
Please ensure to create the index `submission-test` or the index specified in the environment variable `ES_INDEX_TEST` before running the Integration tests. You could re-use the existing scripts to create index but you would need to set the below environment variable
90+
91+
```
92+
export ES_INDEX=submission-test
93+
```
94+
95+
#### Running unit tests and coverage
96+
97+
To run unit tests alone
98+
99+
```
100+
npm run test
101+
```
102+
103+
To run unit tests with coverage report
104+
105+
```
106+
npm run cov
107+
```
108+
109+
#### Running integration tests and coverage
110+
111+
To run integration tests alone
112+
113+
```
114+
npm run e2e
115+
```
116+
117+
To run integration tests with coverage report
118+
119+
```
120+
npm run cov-e2e
121+
```
122+
123+
80124
## Verification
81125

82126
- start kafka server, start elasticsearch, initialize Elasticsearch, start processor app

config/default.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/**
2-
* The configuration file.
2+
* The default configuration file.
33
*/
4-
const AWS = require('aws-sdk')
5-
const httpAWSes = require('http-aws-es')
64

75
module.exports = {
6+
DISABLE_LOGGING: process.env.DISABLE_LOGGING || false, // If true, logging will be disabled
87
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
98

109
KAFKA_URL: process.env.KAFKA_URL || 'localhost:9092',
@@ -17,18 +16,11 @@ module.exports = {
1716
UPDATE_DATA_TOPIC: process.env.UPDATE_DATA_TOPIC || 'submission.notification.update',
1817
DELETE_DATA_TOPIC: process.env.DELETE_DATA_TOPIC || 'submission.notification.delete',
1918

20-
// see https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/configuration.html
21-
// for full config details, for SSL connection, see the ssl field details in above page
22-
ELASTICSEARCH_CONFIG: {
23-
apiVersion: process.env.ES_API_VERSION || '6.3',
24-
host: process.env.ELASTICSEARCH_HOST || 'localhost:9200',
25-
connectionClass: httpAWSes,
26-
amazonES: {
27-
region: process.env.AWS_REGION || 'us-east-1',
28-
credentials: new AWS.EnvironmentCredentials('AWS')
29-
}
30-
},
31-
32-
ELASTICSEARCH_INDEX: process.env.ELASTICSEARCH_INDEX || 'submission-index',
33-
ELASTICSEARCH_INDEX_TYPE: process.env.ELASTICSEARCH_INDEX_TYPE || 'submission'
19+
esConfig: {
20+
HOST: process.env.ES_HOST,
21+
AWS_REGION: process.env.AWS_REGION || 'us-east-1', // AWS Region to be used if we use AWS ES
22+
API_VERSION: process.env.ES_API_VERSION || '6.3',
23+
ES_INDEX: process.env.ES_INDEX || 'submission-test',
24+
ES_TYPE: process.env.ES_TYPE || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
25+
}
3426
}

config/production.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Production configuration file
3+
*/
4+
5+
module.exports = {
6+
LOG_LEVEL: process.env.LOG_LEVEL || 'info'
7+
}

config/test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Configuration file to be used while running tests
3+
*/
4+
5+
module.exports = {
6+
DISABLE_LOGGING: false, // If true, logging will be disabled
7+
LOG_LEVEL: 'debug',
8+
esConfig: {
9+
ES_HOST: process.env.ES_HOST || 'https://test.es.com',
10+
ES_INDEX: process.env.ES_INDEX_TEST || 'submission-test',
11+
ES_TYPE: process.env.ES_TYPE_TEST || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
12+
}
13+
}

docker/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Use the base image with Node.js 8.11.3
2+
FROM node:8.11.3
3+
4+
# Copy the current directory into the Docker image
5+
COPY . /submission-processor-es
6+
7+
# Set working directory for future use
8+
WORKDIR /submission-processor-es
9+
10+
# Install the dependencies from package.json
11+
RUN npm install

docker/docker-compose.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
version: "2"
1+
version: '3'
22
services:
3-
esearch:
4-
image: "docker.elastic.co/elasticsearch/elasticsearch:6.3.1"
5-
ports:
6-
- "9200:9200"
3+
submission-processor-es:
4+
build:
5+
context: ../
6+
dockerfile: docker/Dockerfile
7+
env_file:
8+
- api.env
9+
command: npm start
10+
network_mode: "host"

docker/sample.api.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
AWS_ACCESS_KEY_ID=<AWS Access Key ID>
2+
AWS_SECRET_ACCESS_KEY=<AWS Secret Access Key>
3+
ES_HOST=<ES Host Endpoint>

0 commit comments

Comments
 (0)