Skip to content

konstantinTarletski/game-sys-test-task

Repository files navigation

GameSys test task

This test task consist of one application, which read RSS news from configurable URL, process each news data and store it to database.

List of RSS channels can be found here : https://edition.cnn.com/services/rss/

Processing data performed like this : Title of the news transformed to uppercase and content of it in reversed order. Also all fields trimmed to 1000 letters. RSS news can be processed manually or by scheduler, which delay may be also configured also.

This application have API to control it and view results.

Architecture

I was choosing between "JDBCTemplate" and "ResultSet" and decided to build application on "ResultSet". It seems to me more "interesting". Knowing if that will be a "real" application maybe I will decide to use "JDBCTemplate” or some other technology. But for test task "ResultSet" is more interesting, I think.

For not having code duplication with opening and close connection and "Statement" I create "base" class for every SQL operation. That is why structure become not usual.

But not usual not means bad. Application have flexible structure and we can easy add new DAO for other tables if we need in future. Application structure will not create new "SQL instances" if we add new DAO.

Of course, there can be done some improvements. For example, for now it is impossible to pass parameters for "SELECT" operations and "SQL" can be taken only from "Resource" what is not very convenient. But there was no need to add more complex solutions. Because this task has certain requirements. And, for example, having only 3 different SQLs, put 2 of them in one place and 1 to another, not logical in scope of this task.

Used technologies and tools

  • Java 11
  • Gradle
  • H2 database
  • Gradle
  • SpringBoot 2
  • Lombok
  • Docker
  • Docker-compose
  • Swagger
  • Some other small spring embedded things

Rss-reader API

All API available on swagger by link: localhost:8815/swagger-ui.html (Cluster stopped. Ask me to run, if needed.)

  • To process RSS news manually you can call this endpoint: GET http://localhost:8815/api/rss-reader/process-rss. It will execute same logic, that scheduler do. But only once.

  • To enable/disable scheduler for reading RSS news from you can use this endpoint.

    GET http://localhost:8815/api/rss-reader/enable-scheduler?enabled=false

    Where enabled can be true or false

  • To view last 10 database records you can use this endpoint. GET http://localhost:8815/api/rss-reader/read-last-items

All request have basic authentication and username is birkle password is e77d9295f66e4ea9b5aac7bc4ede3dd

Use swagger Authorize button in top right corner !!!

How to run project

This project can be run in 3 ways:

Run with docker-compose

To run this application with "docker-compose" you need just run the command :

docker-compose up -d

Yon do not need even to have Java installed on your local computer, because compilation of the source code take place inside docker images.

All API links will be same like if you run it locally.

Run like local applications

You can start this project like a normal SpringBoot application from console or IDE.

See the results

There are 2 ways to see result data generated by this project:

  • From web API : to view last 10 database records you can use this endpoint. GET http://localhost:8815/api/api/rss-reader/read-last-items

  • From database : you can use H2 console, here is the configuration to it. It also visible from docker-compose

    Link : http://localhost:8815/h2-console/

    JDBC URL: jdbc:h2:tcp://localhost:9090/mem:testdb

    USER : sa

    PASSWORD : <empty>

Tests

I covered in tests service, repository and also "DB" layer, where is written logic to work with database.

For testing I use "Junit" like it written in task description, but in extra I was using "powermock" for "mock" static methods and have ability to cover all "service", "repository" and "db" package methods.

Integration tests I did only for "RssDao" because others classes from service layer can be tested without application context.

Google Kubernetes

I deployed this task to GKE - Google Kubernetes Engine.

I created cluster on zone europe-west4-b because in this zone I can use more resources, if this cluster I will use for other projects.

Also this zone "not far" to Estonia, hope this will minimize delays for cluster traffic for me.

After setup gcloud I used this commands to put this project to cloud:

docker build -t gcr.io/kostja-test-project/game-sys-test-task .
gcloud auth configure-docker
docker push gcr.io/kostja-test-project/game-sys-test-task
kubectl create deployment game-sys-test-task --image=gcr.io/kostja-test-project/game-sys-test-task
kubectl expose deployment game-sys-test-task --type=LoadBalancer --port 80 --target-port 8815

After that this task is available by link : http://34.90.176.189/swagger-ui.html (Cluster stopped. Ask me to run, if needed.)

I "expose" this task like "LoadBalancer", I did not use "ingres". I did so to simplify configuration, and because for now this project is only in the cloud. And there is no any need to do ingres because no any resources need to be "expose" from cluster. In future I will do ingres, for sure.

Security

I decided to use basic authentication because it is not hard to implement, shows my knowledge of Spring Security and it is enough for ths project. I understand that basic authentication not recommended to use, especially with http (not https). But this project do not have any confidential or useful data. So nothing can be stolen or spoiled in this project. Also implementing JWT authentication much more complex. Ii is need to implement JWT token encoding/decoding/validation/issue. Also it is needed to implement issue of refresh token and think about logout of the user. All this can be more complex than this task is. So I decided not no complicate this test task.

About

GameSys test task

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published