Skip to content

Commit

Permalink
Merge pull request #16 from viniciusfcf/viniciusfcf
Browse files Browse the repository at this point in the history
viniciusfcf - Quarkus + Postgres
  • Loading branch information
zanfranceschi committed Feb 6, 2024
2 parents 6e7890b + c8381b9 commit 45673d0
Show file tree
Hide file tree
Showing 31 changed files with 1,815 additions and 0 deletions.
5 changes: 5 additions & 0 deletions participantes/viniciusfcf/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
!target/quarkus-app/*
43 changes: 43 additions & 0 deletions participantes/viniciusfcf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
release.properties
.flattened-pom.xml

# Eclipse
.project
.classpath
.settings/
bin/

# IntelliJ
.idea
*.ipr
*.iml
*.iws

# NetBeans
nb-configuration.xml

# Visual Studio Code
.vscode
.factorypath

# OSX
.DS_Store

# Vim
*.swp
*.swo

# patch
*.orig
*.rej

# Local environment
.env

# Plugin directory
/.quarkus/cli/plugins/
1 change: 1 addition & 0 deletions participantes/viniciusfcf/.mvn/wrapper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
maven-wrapper.jar
98 changes: 98 additions & 0 deletions participantes/viniciusfcf/.mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.io.IOException;
import java.io.InputStream;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public final class MavenWrapperDownloader
{
private static final String WRAPPER_VERSION = "3.2.0";

private static final boolean VERBOSE = Boolean.parseBoolean( System.getenv( "MVNW_VERBOSE" ) );

public static void main( String[] args )
{
log( "Apache Maven Wrapper Downloader " + WRAPPER_VERSION );

if ( args.length != 2 )
{
System.err.println( " - ERROR wrapperUrl or wrapperJarPath parameter missing" );
System.exit( 1 );
}

try
{
log( " - Downloader started" );
final URL wrapperUrl = new URL( args[0] );
final String jarPath = args[1].replace( "..", "" ); // Sanitize path
final Path wrapperJarPath = Paths.get( jarPath ).toAbsolutePath().normalize();
downloadFileFromURL( wrapperUrl, wrapperJarPath );
log( "Done" );
}
catch ( IOException e )
{
System.err.println( "- Error downloading: " + e.getMessage() );
if ( VERBOSE )
{
e.printStackTrace();
}
System.exit( 1 );
}
}

private static void downloadFileFromURL( URL wrapperUrl, Path wrapperJarPath )
throws IOException
{
log( " - Downloading to: " + wrapperJarPath );
if ( System.getenv( "MVNW_USERNAME" ) != null && System.getenv( "MVNW_PASSWORD" ) != null )
{
final String username = System.getenv( "MVNW_USERNAME" );
final char[] password = System.getenv( "MVNW_PASSWORD" ).toCharArray();
Authenticator.setDefault( new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication( username, password );
}
} );
}
try ( InputStream inStream = wrapperUrl.openStream() )
{
Files.copy( inStream, wrapperJarPath, StandardCopyOption.REPLACE_EXISTING );
}
log( " - Downloader complete" );
}

private static void log( String msg )
{
if ( VERBOSE )
{
System.out.println( msg );
}
}

}
18 changes: 18 additions & 0 deletions participantes/viniciusfcf/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
13 changes: 13 additions & 0 deletions participantes/viniciusfcf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Rinha de Backend 2024-Q1

### Vinicius Ferraz

Github: [@viniciusfcf](https://github.com/viniciusfcf)
Twitter: [@viniciusfcf](https://twitter.com/viniciusfcf)
Repositório: [https://github.com/viniciusfcf/rinha-de-backend-2024-q1/](https://github.com/viniciusfcf/rinha-de-backend-2024-q1)


### Stack: Quarkus com Postgres
- Quarkus 🚀
- Postgres
- Nginx
2 changes: 2 additions & 0 deletions participantes/viniciusfcf/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./mvnw clean package -DskipTests -Dquarkus.container-image.build=true
docker build -f src/main/docker/Dockerfile.jvm -t viniciusfcf/rinha-backend-2024q1-jvm:latest .
2 changes: 2 additions & 0 deletions participantes/viniciusfcf/clean_containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker rm $(docker ps --filter status=exited -q)
docker volume rm $(docker volume ls -q)
74 changes: 74 additions & 0 deletions participantes/viniciusfcf/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: "3.6"

services:
api01: &api
# Lembre-se de que seu serviço HTTP deve estar hospedado num repositório
# publicamente acessível! Ex.: hub.docker.com
image: viniciusfcf/rinha-backend-2024q1:latest
hostname: api01
network_mode: "host"
environment:
- QUARKUS_HTTP_PORT=8081
depends_on:
db:
condition: service_healthy
deploy:
resources:
limits:
cpus: "0.25"
memory: "100MB"
ulimits:
nproc: 65535
nofile:
soft: 1000000
hard: 1000000

api02:
# Essa sintaxe reusa o que foi declarado em 'api01'.
<<: *api
hostname: api02
environment:
- QUARKUS_HTTP_PORT=8082

nginx:
image: nginx:latest
network_mode: "host"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- api01
- api02
deploy:
resources:
limits:
cpus: "0.2"
memory: "50MB"

db:
image: postgres:latest
hostname: db
environment:
- POSTGRES_PASSWORD=123
- POSTGRES_USER=admin
- POSTGRES_DB=rinha
command: postgres -c 'max_connections=30'
network_mode: "host"
volumes:
- ./import.sql:/docker-entrypoint-initdb.d/script.sql
deploy:
resources:
limits:
# Note que a soma de todos os limites dos serviços
# aqui declarados é de 1.5 unidades de CPU e 550MB
# de memória. A distribuição feita aqui é apenas
# um exemplo – distribua como quiser.
cpus: "0.8"
memory: "100MB"
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 5s
timeout: 5s
retries: 20
start_period: 10s


41 changes: 41 additions & 0 deletions participantes/viniciusfcf/import.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
CREATE TABLE public.cliente (
id SERIAL PRIMARY KEY,
limite INTEGER NOT NULL -- poderia ter tirado, n tirei por preguiça
);

CREATE TABLE public.saldocliente (
id INTEGER PRIMARY KEY NOT NULL, -- id do cliente
-- Dupliquei, é a vida.
limite INTEGER NOT NULL,
saldo INTEGER NOT NULL
);

CREATE TABLE public.transacao (
id SERIAL PRIMARY KEY,
cliente_id INTEGER NOT NULL,
valor INTEGER NOT NULL,
tipo CHAR(1) NOT NULL,
descricao VARCHAR(10) NOT NULL,
realizada_em TIMESTAMP NOT NULL,
-- Dupliquei, é a vida.
limite INTEGER NOT NULL,
saldo INTEGER NOT NULL
);


INSERT INTO public.cliente (id, limite)
VALUES
(1, 1000 * 100),
(2, 800 * 100),
(3, 10000 * 100),
(4, 100000 * 100),
(5, 5000 * 100);

INSERT INTO public.saldocliente (id, limite, saldo)
VALUES
(1, 1000 * 100, 0),
(2, 800 * 100, 0),
(3, 10000 * 100, 0),
(4, 100000 * 100, 0),
(5, 5000 * 100, 0);

2 changes: 2 additions & 0 deletions participantes/viniciusfcf/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
update public.cliente set saldo = 0;
delete public.transacoes;
Loading

0 comments on commit 45673d0

Please sign in to comment.