Skip to content

Commit

Permalink
Picocli app
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Oct 30, 2024
1 parent 2bcaf37 commit 4e74422
Show file tree
Hide file tree
Showing 42 changed files with 1,670 additions and 946 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ You will download the load application, install it and run it.

== Give me some load!

In the `super-heroes/load-super-heroes` directory, there is an application that is **NOT** a Quarkus application.
It's a simple Java app that simulates users interacting with the system so it generates some load.
In the `super-heroes/cli-super-heroes` directory, there is a command line Quarkus application .
This application simulates users interacting with the system so it generates some load.

== Looking at Some Code

The `SuperHeroesLoad` class is just a `main` that executes the `FightScenario`, `HeroScenario` and `VillainScenario` in different threads.
The `CLIMain` class is just a Picocli extension command line application that executes the `FightScenario`, `HeroScenario` and `VillainScenario`,
on the same thread but randomly execuring 3 different random calls to the 3 REST APIs.
For example, if you look at the `HeroScenario`, you will see that it's just a suit of HTTP calls on the Hero API:

[source,indent=0]
----
include::{projectdir}/load-super-heroes/src/main/java/io/quarkus/workshop/superheroes/load/HeroScenario.java[tag=adocScenario]
include::{projectdir}/cli-super-heroes/src/main/java/io/quarkus/workshop/superheroes/load/scenarios/HeroScenario.java[tag=adocScenario]
----

== Running the Load Application
Expand All @@ -30,12 +31,12 @@ Time to compile and start the load application using:

[source,shell]
----
./mvnw compile
./mvnw exec:java
./mvnw package
java -jar ./target/quarkus-app/quarkus-run.jar -s
----
--

You will see the following logs:
You will see the following logs. To stop the load, write something and press Enter key.

[source,shell]
----
Expand Down
3 changes: 2 additions & 1 deletion quarkus-workshop-super-heroes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<module>super-heroes/rest-fights</module>
<module>super-heroes/event-statistics</module>
<module>super-heroes/rest-narration</module>
<module>super-heroes/load-super-heroes</module>
<module>super-heroes/cli-super-heroes</module>
</modules>
</profile>
<profile>
Expand All @@ -141,6 +141,7 @@
<module>super-heroes/rest-fights</module>
<module>super-heroes/event-statistics</module>
<module>super-heroes/rest-narration</module>
<module>super-heroes/cli-super-heroes</module>
<module>docs</module>
</modules>
</profile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
!target/quarkus-app/*
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/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
maven-wrapper.jar
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 );
}
}

}
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
Loading

0 comments on commit 4e74422

Please sign in to comment.