Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3b8b2b5
feat: add inspection server with akes framework
ErnestMatskevich May 20, 2025
3641685
Update pom.xml
ErnestMatskevich May 21, 2025
9cb76ee
Add unit test and qulice
ErnestMatskevich May 21, 2025
a22a974
add license in package-info.java
ErnestMatskevich May 22, 2025
1cf9618
Merge branch 'objectionary:master' into 500
ErnestMatskevich May 22, 2025
f649742
Add simple test for Inspect.java
ErnestMatskevich May 22, 2025
642cbea
Merge branch 'master' into 500
ErnestMatskevich May 24, 2025
dd74c55
Add profile to creating inspect.jar file
ErnestMatskevich May 24, 2025
9097c93
Merge branch 'master' into 500
ErnestMatskevich May 28, 2025
5e205ea
fix: add missing comma in package.json
ErnestMatskevich May 28, 2025
934ca18
Merge branch 'objectionary:master' into 500
ErnestMatskevich May 29, 2025
e9382b5
Added asserts to test
ErnestMatskevich May 29, 2025
057fee3
Update pom.xml
ErnestMatskevich May 29, 2025
314b44d
Rename variables in inspect.js
ErnestMatskevich May 30, 2025
59df1e8
fix: use object shorthand in test_inspect.js
ErnestMatskevich May 30, 2025
9091b4b
Rewrite InspectTest with proper waiting
ErnestMatskevich May 30, 2025
969012b
Update Inspect.java
ErnestMatskevich May 30, 2025
3e593de
Build inspect.jar once with Maven package
ErnestMatskevich Jun 1, 2025
9f5edf8
Clean up InspectTest.java
ErnestMatskevich Jun 4, 2025
0a74e73
Merge branch 'master' into 500
ErnestMatskevich Jun 22, 2025
b6fca8b
Update package-lock.json
ErnestMatskevich Jun 22, 2025
cb7bcfa
Update pom.xml
ErnestMatskevich Jun 22, 2025
ca58081
Update pom.xml
ErnestMatskevich Jun 22, 2025
5be56ca
Update pom.xml
ErnestMatskevich Jun 23, 2025
e0d206d
Merge branch 'master' into 500
ErnestMatskevich Jun 23, 2025
5e873e8
Remove empty lines in inspect.js
ErnestMatskevich Jun 23, 2025
956fa4f
Create new top-level folder inspect
ErnestMatskevich Jun 23, 2025
b33189f
Remove InspectTest.java
ErnestMatskevich Jun 24, 2025
d6992f9
Add puzzle in inspect.js
ErnestMatskevich Jun 24, 2025
56a4e0b
Update inspect.js
ErnestMatskevich Jun 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions mvnw/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<version>5.12.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>eoc</finalName>
Expand Down Expand Up @@ -97,6 +103,13 @@
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<excludes>
<exclude>org/eolang/Inspect.class</exclude>
<exclude>org/eolang/Inspect$*.class</exclude>
<exclude>**/InspectTest.class</exclude>
<exclude>**/InspectTest$*.class</exclude>
<exclude>**/package-info.class</exclude>
</excludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
Expand Down Expand Up @@ -130,4 +143,51 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>inspect</id>
Copy link
Member

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?

Copy link
Member

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?

<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.takes</groupId>
<artifactId>takes</artifactId>
<version>1.24.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>make-inspect-jar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/inspect.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>org.eolang.Inspect</mainClass>
</manifest>
</archive>
<finalName>inspect</finalName>
<attach>false</attach>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
39 changes: 39 additions & 0 deletions mvnw/src/assembly/inspect.xml
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>
49 changes: 49 additions & 0 deletions mvnw/src/main/java/org/eolang/Inspect.java
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() {
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Author

@ErnestMatskevich ErnestMatskevich May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@volodya-lombrozo I added private to constructor to follow qulice rules when qulice plugin was part of my code. Without private constructor, qulice spawned this error:

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 main(). I deleted misunderstinding comment and saved constructor itself to follow qulice rule in future, when plugin will be added in project.

All changes regarding to Inspect.java file were done in this commit

Copy link
Member

Choose a reason for hiding this comment

The 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());
}
}
11 changes: 11 additions & 0 deletions mvnw/src/main/java/org/eolang/package-info.java
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;
66 changes: 66 additions & 0 deletions mvnw/src/test/java/org/eolang/InspectTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.setDaemon(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ErnestMatskevich Why do we need this? From https://stackoverflow.com/a/17878439/10423604:

Any thread created by main thread, which runs main method in Java is by default non daemon because Thread inherits its daemon nature from the Thread which creates it i.e. parent Thread and since main thread is a non daemon thread, any other thread created from it will remain non-daemon until explicitly made daemon by calling setDaemon(true).


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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ErnestMatskevich Here you just check the the thread is alive. It tells nothing about the server availability.
https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#isAlive--

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@volodya-lombrozo Yes, the purpose of this test now is just check that server is starting without any errors. The availability of server is cheking in test_inspect.js file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ErnestMatskevich How do you know there aren't errors? It may be that the server didn't actually start, but the thread is still alive.

is(true)
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ErnestMatskevich Can we remove empty lines, please? It's a code smell.

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)
);
}
}
10 changes: 10 additions & 0 deletions mvnw/src/test/java/org/eolang/package-info.java
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;
Loading
Loading