-
Notifications
You must be signed in to change notification settings - Fork 39
500, adding entry point to inspect command #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 25 commits
3b8b2b5
3641685
9cb76ee
a22a974
1cf9618
f649742
642cbea
dd74c55
9097c93
5e205ea
934ca18
e9382b5
057fee3
314b44d
59df1e8
9091b4b
969012b
3e593de
9f5edf8
0a74e73
b6fca8b
cb7bcfa
ca58081
5be56ca
e0d206d
5e873e8
956fa4f
b33189f
d6992f9
56a4e0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <!-- | ||
| * SPDX-FileCopyrightText: Copyright (c) 2022-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| --> | ||
| <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 | ||
| http://maven.apache.org/xsd/assembly-1.1.2.xsd"> | ||
| <id>inspect</id> | ||
| <formats> | ||
| <format>jar</format> | ||
| </formats> | ||
| <includeBaseDirectory>false</includeBaseDirectory> | ||
| <fileSets> | ||
| <fileSet> | ||
| <directory>${project.build.outputDirectory}</directory> | ||
| <includes> | ||
| <include>org/eolang/Inspect.class</include> | ||
| <include>org/eolang/Inspect$*.class</include> | ||
| <include>org/eolang/package-info.class</include> | ||
| </includes> | ||
| <outputDirectory>/</outputDirectory> | ||
| </fileSet> | ||
| </fileSets> | ||
| <dependencySets> | ||
| <dependencySet> | ||
| <scope>compile</scope> | ||
| <useProjectArtifact>false</useProjectArtifact> | ||
| <unpack>true</unpack> | ||
| <useTransitiveDependencies>true</useTransitiveDependencies> | ||
| <useTransitiveFiltering>false</useTransitiveFiltering> | ||
| <includes> | ||
| <include>org.takes:takes</include> | ||
| <include>org.cactoos:cactoos</include> | ||
| </includes> | ||
| <outputDirectory>/</outputDirectory> | ||
| </dependencySet> | ||
| </dependencySets> | ||
| </assembly> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2022-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| package org.eolang; | ||
|
|
||
| import java.io.IOException; | ||
| import org.takes.Request; | ||
| import org.takes.Response; | ||
| import org.takes.Take; | ||
| import org.takes.facets.fork.FkRegex; | ||
| import org.takes.facets.fork.TkFork; | ||
| import org.takes.http.FtBasic; | ||
| import org.takes.rq.RqPrint; | ||
| import org.takes.rs.RsText; | ||
|
|
||
| /** | ||
| * HTTP inspection server. | ||
| * @since 0.29.0 | ||
| */ | ||
| public final class Inspect { | ||
| /** | ||
| * Prevents instantiation (required by qulice UseUtilityClass rule). | ||
| */ | ||
| private Inspect() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ErnestMatskevich Why do we need to hide this constructor? What is the purpose for it? I don't think this class is actually a "utility" class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I added All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning. (UseUtilityClass) I agree that it is not utility class since there is a All changes regarding to Inspect.java file were done in this commit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ErnestMatskevich Great thanks for the explanation. Now it's clear. |
||
| // Intentionally empty | ||
| } | ||
|
|
||
| /** | ||
| * Main entry point. | ||
| * @param args Command line arguments | ||
| * @throws IOException If server fails to start | ||
| */ | ||
| public static void main(final String... args) throws IOException { | ||
| new FtBasic( | ||
| new TkFork( | ||
| new FkRegex( | ||
| "/echo", | ||
| (Take) req -> new RsText(new RqPrint(req).printBody()) | ||
| ), | ||
| new FkRegex( | ||
| "/", | ||
| new RsText("Server is running. Use /echo endpoint") | ||
| ) | ||
| ), | ||
| 8080 | ||
| ).start(() -> Thread.currentThread().isInterrupted()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2022-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
|
|
||
| /** | ||
| * EO inspection utilities. | ||
| * Includes HTTP server for testing (under developing). | ||
| * @since 0.29.0 | ||
| */ | ||
| package org.eolang; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2022-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| package org.eolang; | ||
|
|
||
| import java.io.IOException; | ||
| import org.junit.jupiter.api.Test; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
| /** | ||
| * Smoke test to ensure that {@link Inspect} server starts without throwing exceptions. | ||
| * <p> | ||
| * This test launches the server in a separate thread to verify startup stability. | ||
| * Functional behavior is tested in {@code test_inspect.js}. | ||
| * </p> | ||
| * | ||
| * @since 0.29.0 | ||
| */ | ||
| final class InspectTest { | ||
| /** | ||
| * Verifies that {@link Inspect#main(String[])} starts without errors. | ||
| * | ||
| * @throws Exception If the thread is interrupted | ||
| */ | ||
| @Test | ||
| void runsWithoutExceptions() throws Exception { | ||
| final Thread server = new Thread( | ||
| new Runnable() { | ||
| @Override | ||
| public void run() { | ||
| try { | ||
| Inspect.main(); | ||
| } catch (final IOException ex) { | ||
| throw new IllegalStateException("IOException while starting server", ex); | ||
| } | ||
| } | ||
| } | ||
| ); | ||
| server.start(); | ||
| final long start = System.currentTimeMillis() + 10_000L; | ||
| while (System.currentTimeMillis() < start && !server.isAlive()) { | ||
| Thread.sleep(100); | ||
| } | ||
| assertThat( | ||
| "Server thread should be running after start", | ||
| server.isAlive(), | ||
|
||
| is(true) | ||
| ); | ||
| server.interrupt(); | ||
| final long stop = System.currentTimeMillis() + 5_000L; | ||
| while (System.currentTimeMillis() < stop && server.isAlive()) { | ||
| Thread.sleep(100); | ||
| } | ||
| assertThat( | ||
| "Server thread should be terminated after interrupt", | ||
| server.isAlive(), | ||
| is(false) | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2022-2025 Objectionary.com | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
|
|
||
| /** | ||
| * Unit tests for Inspect server. | ||
| * @since 0.29.0 | ||
| */ | ||
| package org.eolang; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ErnestMatskevich I can't find the place in the code where you use this Maven profile. Can you give me a link, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ErnestMatskevich What about this one?