Giter Club home page Giter Club logo

prime-generator's Introduction

prime-generator

A very simple way to create a list of prime numbers up to a given number.

Discussion

I've decided to keep all the code simple, but tested. So, I can iterate it by the time.

First, I have created a component to provide the prime numbers. It contains the a grpc server running in the port 9999 to retrieve the numbers for a given client.

Then a proxy which connects with the prime number server and expose a rest interface to the web running in the port 8080.

Both, in localhost.

All complexity and validation regarding creating and dealing with bad integers are on prime-number.

The prime number generator is not optimized, and might have problems of OoM or long wait time if the argument is a big number. It is because I decided to keep it simple and delivery the value on the first iteration. Then, improve performance if necessary.

Another opportunity of improvement is improve the resilience between the proxy and the prime-server. In a event of disconnection, one will need to restart both servers manually.

The web interface is:

/primes/<a given number>

Then the web servicer will return:

2,... to the last prime up to the number.

Examples:

/primes/17 will return 2,3,5,7,11,13,17.

/primes/21 returning 2,3,5,7,11,13,17,19.

/primes/3 getting 2,3.

Errors

/primes/a

Will return 400, with a message saying that it failed to convert a to integer

/primes

will return 404

/primes/1

will return 400, and the message saying that 1 is not valid. That is the same message for any number lower than 2.

Any 500 or other error, can be related to connection between the proxy and the server, or another service running on the same port. I'll be more than happy on helping debug any strange case.

Requirements

  • Java version 11
  • Maven 3.6

before you run any command

mvn clean install

That is very important to make sure the java code of the protobuf is created.

running all unit tests

mvn test

running the integration test

First start the servers (refers to the next section).

then

mvn -Prun-integration-tests clean verify

Starting the servers

First you need to start the prime-number-server

cd prime-number-server

mvn exec:java -Dexec.mainClass="com.romulojales.prime.PrimeServer"

If you get this message, that means you are good:

[com.romulojales.prime.PrimeServer.main()] INFO com.romulojales.prime.PrimeServer - Starting the GRPC server
[com.romulojales.prime.PrimeServer.main()] INFO com.romulojales.prime.PrimeServer - The GRPC server has been started

Then the proxy

open another terminal, go back to the root folder of the project, then

cd proxy-service

mvn spring-boot:run

then you should see the spring's logo

Folders

  • integration-tests, contains the tests that requires both server running
  • prime-number-server, the grpc server that generates the prime numbers
  • protobuf, the grpc specification
  • proxy-service, the spring boot component that exposes the rest endpoint and talks to the prime-number-server

prime-generator's People

Contributors

romulojales avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.