Skip to content
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

#533 a lot of stuff #555

Closed
wants to merge 84 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
e62317b
setup resilience4j
mageddo Aug 30, 2024
742a0e8
specifying circuit breaker strategy name
mageddo Aug 30, 2024
6ab3d76
creating agnostic interface to support multiple circuit breaker strat…
mageddo Aug 30, 2024
460233a
fixme
mageddo Aug 30, 2024
d9c2852
sppliting circuit breaker factory
mageddo Aug 30, 2024
d05ff95
refactoring is done
mageddo Aug 30, 2024
a7dd4c0
test is passing
mageddo Aug 30, 2024
5869154
test is passing
mageddo Aug 30, 2024
34544f2
test is passing
mageddo Aug 30, 2024
fda3d97
refactoring package
mageddo Aug 30, 2024
99588e0
[Gradle Release Plugin] - new version commit: '3.25.11-snapshot'.
mageddo Aug 30, 2024
50bb180
release notes
mageddo Aug 30, 2024
690c4c4
Merge branch 'feat/533' into feat/533-circuit-breaker-service-refacto…
mageddo Aug 30, 2024
10e6a77
[Gradle Release Plugin] - new version commit: '3.25.12-snapshot'.
mageddo Aug 30, 2024
3b17f26
release notes
mageddo Aug 30, 2024
d6c3c5f
merging
mageddo Sep 2, 2024
928fcd3
fixme note
mageddo Sep 2, 2024
b817612
fixme note
mageddo Sep 2, 2024
a087aff
refactoring to support multiple delegates
mageddo Sep 2, 2024
808c554
refactoring name
mageddo Sep 2, 2024
cfb3068
refactoring
mageddo Sep 2, 2024
86d9531
implementing non resilient strategy
mageddo Sep 2, 2024
6b5b0c4
refactoring and test
mageddo Sep 2, 2024
5790939
removing unnecessary test
mageddo Sep 2, 2024
6813d00
merging
mageddo Sep 2, 2024
a7704d6
refactoring and fixing test
mageddo Sep 2, 2024
4bf6cf6
creating a comp test to check integratio between modules
mageddo Sep 2, 2024
940f72d
new test detecting bug
mageddo Sep 2, 2024
9e21a83
merging
mageddo Sep 2, 2024
3780b14
fixing bug and release notes
mageddo Sep 2, 2024
4d4dd8f
[Gradle Release Plugin] - new version commit: '3.25.14-snapshot'.
mageddo Sep 2, 2024
3ed7e55
comp test wont be able to be mocked, creating a int test instead
mageddo Sep 2, 2024
556d3a5
creating dps binary executable finder
mageddo Sep 2, 2024
0eb1212
configuring sandbox
mageddo Sep 2, 2024
1e86f19
creating sandbox and tests
mageddo Sep 2, 2024
bedd1c0
fixing test
mageddo Sep 2, 2024
46bd9a5
setup execution
mageddo Sep 4, 2024
05188d1
creating a dummy signal based healthcheck
mageddo Sep 4, 2024
2987357
creating a dummy signal based healthcheck
mageddo Sep 4, 2024
82ff1d4
creating a dummy signal based healthcheck
mageddo Sep 4, 2024
5d5f883
registering and testing eager beans
mageddo Sep 4, 2024
97dd0eb
fixing test
mageddo Sep 4, 2024
37cf1a3
creating a lot of features related to watch process execution
mageddo Sep 4, 2024
8564b43
new way to excute command line and specify stream handler
mageddo Sep 4, 2024
cee15ac
killing processes after test execution
mageddo Sep 4, 2024
fa4f353
fixing test
mageddo Sep 4, 2024
bf8d077
fixing test
mageddo Sep 4, 2024
32a8a76
fixing test
mageddo Sep 4, 2024
57edb56
fixing test
mageddo Sep 4, 2024
6d79c1a
generating all jar dep for int test automatically
mageddo Sep 4, 2024
a97c34f
Fixing int test binary executor
mageddo Sep 4, 2024
8207f51
unnecessary method
mageddo Sep 4, 2024
d2f2fd3
Merge remote-tracking branch 'origin/master' into feat/533-a-lot-of-s…
mageddo Sep 4, 2024
4156f2d
merging
mageddo Sep 4, 2024
ff0718f
refactoring test to use json config file only
mageddo Sep 4, 2024
9fb069f
all working
mageddo Sep 4, 2024
5837b4c
adjusting test
mageddo Sep 4, 2024
04c4214
fixing test
mageddo Sep 4, 2024
98390e3
fixing bugs and creating tests
mageddo Sep 4, 2024
d6367a6
refactoring inner class to upper
mageddo Sep 4, 2024
0f839aa
Merge remote-tracking branch 'origin/master' into feat/533-a-lot-of-s…
mageddo Sep 5, 2024
8660a11
reduce native image optimization for int test to reduce build time
mageddo Sep 5, 2024
7452385
fixing test
mageddo Sep 5, 2024
217af38
unnecessary
mageddo Sep 5, 2024
8373d9b
Merge remote-tracking branch 'origin/master' into feat/533-a-lot-of-s…
mageddo Sep 5, 2024
0022c2f
Merge remote-tracking branch 'origin/master' into feat/533-a-lot-of-s…
mageddo Sep 5, 2024
c430ab1
clean code
mageddo Sep 5, 2024
253c6bb
deleteing unnecessary file
mageddo Sep 5, 2024
934ff24
updating build gradle
mageddo Sep 5, 2024
5a9f6f7
Merge remote-tracking branch 'origin/master' into feat/533-a-lot-of-s…
mageddo Sep 5, 2024
01e616e
release notes
mageddo Sep 5, 2024
bc0a01d
[Gradle Release Plugin] - new version commit: '3.29.0-snapshot'.
mageddo Sep 5, 2024
9ac2c14
Creating support for testing DPS really like a integration test, crat…
mageddo Sep 5, 2024
9816e33
clean code
mageddo Sep 5, 2024
7df2fc0
clean code
mageddo Sep 5, 2024
54f77da
configuring templates
mageddo Sep 5, 2024
66f4b37
configuring templates
mageddo Sep 5, 2024
14fc703
option to get answer ip
mageddo Sep 5, 2024
8a9ec59
merging
mageddo Sep 5, 2024
5fa442b
Merge remote-tracking branch 'origin/master' into feat/533-a-lot-of-s…
mageddo Sep 5, 2024
7e4b0b5
merging
mageddo Sep 5, 2024
998e302
clean code
mageddo Sep 5, 2024
9b9e102
deleting healthcheck feature
mageddo Sep 5, 2024
d8ae984
Revert "deleting healthcheck feature"
mageddo Sep 5, 2024
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ graalvmNative {

configureEach {
if(it.name == "intTest"){
println "> configuring for: ${it.getName()}"
println "> configuring for: ${it.getName()}"
buildArgs.add("-Ob")
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/mageddo/dnsproxyserver/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class App {
private final String[] args;
private Config config;
private ConfigFlag flags;
private Context context;

public App(String[] args) {
this.args = args;
Expand Down Expand Up @@ -51,10 +52,12 @@ void mustStart() {

this.checkExitCommands();

this.config = this.findConfig(args);
this.config = this.findConfig(this.args);

this.setupLogs();

log.trace("pid={}", ProcessHandle.current().pid());

this.startContext();

// todo install as service
Expand All @@ -79,11 +82,9 @@ void setupLogs() {
}

void startContext() {
final var context = Context.create();

// start webserver
// start dns server
context.start();
Context.create()
.start()
;
}

void checkExitCommands() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mageddo.dnsproxyserver.di.module;

import com.mageddo.di.Eager;
import com.mageddo.dnsproxyserver.healthcheck.entrypoint.HealthCheckSignalEntrypoint;
import com.mageddo.dnsproxyserver.in.entrypoint.InputStreamEntrypoint;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ElementsIntoSet;
Expand All @@ -13,7 +15,11 @@ public class ModuleEager {
@Provides
@Singleton
@ElementsIntoSet
Set<Eager> beans() {
return Set.of();
Set<Eager> beans(
HealthCheckSignalEntrypoint b1, InputStreamEntrypoint b2
) {
return Set.of(
b1, b2
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mageddo.dnsproxyserver.healthcheck;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.inject.Inject;
import javax.inject.Singleton;

@Slf4j
@Singleton
@RequiredArgsConstructor(onConstructor = @__({@Inject}))
public class HealthCheck {
public boolean isHealth(){
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.mageddo.dnsproxyserver.healthcheck.entrypoint;

import com.mageddo.di.Eager;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import sun.misc.Signal;

import javax.inject.Inject;
import javax.inject.Singleton;

@Slf4j
@Singleton
@RequiredArgsConstructor(onConstructor = @__({@Inject}))
public class HealthCheckSignalEntrypoint implements Eager {

private static final String USER_DEFINED_SIGNAL = "USR1";
private final HealthCheckStreamEntrypoint streamEntrypoint;

@Override
public void run() {
this.safeRegisterHandler();
}

void safeRegisterHandler() {
try {
this.registerHandler();
} catch (Throwable t){
log.warn("status=couldntRegisterHandler, msg={}", t.getMessage(), t);
}
}

void registerHandler() {
Signal.handle(new Signal(USER_DEFINED_SIGNAL), sig -> this.streamEntrypoint.printHealthCheck());
log.debug("status=healthCheckSignalRegistered, signal={}", USER_DEFINED_SIGNAL);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mageddo.dnsproxyserver.healthcheck.entrypoint;

import com.mageddo.dnsproxyserver.healthcheck.HealthCheck;
import lombok.RequiredArgsConstructor;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
@RequiredArgsConstructor(onConstructor = @__({@Inject}))
public class HealthCheckStreamEntrypoint {

private final HealthCheck healthCheck;

public void printHealthCheck() {
System.out.printf("dps.healthCheck.health=%b%n", this.healthCheck.isHealth());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.mageddo.dnsproxyserver.in.entrypoint;

import com.mageddo.commons.concurrent.Threads;
import com.mageddo.di.Eager;
import com.mageddo.dnsproxyserver.healthcheck.entrypoint.HealthCheckStreamEntrypoint;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.NoSuchElementException;
import java.util.Scanner;

@Slf4j
@Singleton
@RequiredArgsConstructor(onConstructor = @__({@Inject}))
public class InputStreamEntrypoint implements Eager {

private final HealthCheckStreamEntrypoint healthCheckStreamEntrypoint;
private boolean inShell;

@Override
public void run() {
Thread.ofVirtual()
.start(this::readInputStream)
;
}

private void readInputStream() {
log.debug("status=scanningInputStream");
final var scanner = new Scanner(System.in);
while (true) {
final var line = safeReadLine(scanner);
if (line == null) {
break;
}
this.checkHealthCheck(line);
Threads.sleep(1000 / 15);
}
}

private static String safeReadLine(Scanner scanner) {
try {
return scanner.nextLine();
} catch (NoSuchElementException e) {
return null;
}
}

private void checkHealthCheck(String line) {
if (line.equals("shell")) {
this.inShell = true;
}
if (this.inShell && line.equals("dps.healthCheck.health")) {
this.healthCheckStreamEntrypoint.printHealthCheck();
}
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/mageddo/os/linux/kill/Kill.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mageddo.os.linux.kill;

import com.mageddo.commons.exec.CommandLines;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.exec.CommandLine;

@Slf4j
public class Kill {
public static void sendSignal(int signal, long pid) {
final var result = CommandLines.exec(
new CommandLine("kill")
.addArgument("-" + signal)
.addArgument(pid + "")
);
result.checkExecution();
log.debug("status=signalSentWithSuccess, signal={}, pid={}", signal, pid);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mageddo.dnsproxyserver.healthcheck.entrypoint;

import com.mageddo.dnsproxyserver.healthcheck.HealthCheck;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.mockito.Mockito.doThrow;

@ExtendWith(MockitoExtension.class)
class HealthCheckSignalEntrypointTest {

@Mock
HealthCheck healthCheck;

@Spy
@InjectMocks
HealthCheckSignalEntrypoint entrypoint;

@Test
void mustRegisterHandler() {
this.entrypoint.registerHandler();
}

@Test
void mustCatchFatalErrorsWhenRegisteringHandler() {

doThrow(new AssertionError("mocked error"))
.when(this.entrypoint)
.registerHandler();

this.entrypoint.safeRegisterHandler();

}

}
13 changes: 11 additions & 2 deletions src/test/java/com/mageddo/net/SocketUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class SocketUtilsTest {

@Test
void mustFindRandomFreePort(){
void mustFindRandomFreePort() {
// arrange

// act
Expand All @@ -16,4 +17,12 @@ void mustFindRandomFreePort(){
// assert
assertTrue(port > 0);
}

@Test
void mustFindTwoDifferentPortsForConsecutiveCalls() {
for (int i = 0; i < 3; i++) {
assertNotEquals(SocketUtils.findRandomFreePort(), SocketUtils.findRandomFreePort());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import dagger.sheath.reflection.Signature;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.graalvm.collections.Pair;
import org.graalvm.collections.Pair; // fixme #533 wrong pair, use apache commons lang3

import java.lang.reflect.Method;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package testing.templates.solver.remote;

import com.mageddo.dnsproxyserver.solver.Resolver;

import java.util.List;

public class RemoteResolversTemplates {

public static List<Resolver> buildSuccessAnswerResolverStub() {
return List.of(ResolverTemplates.successAAcmeAnswer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,37 @@

import com.mageddo.dnsproxyserver.solver.Resolver;
import com.mageddo.dnsproxyserver.solver.SimpleResolver;
import lombok.SneakyThrows;
import testing.templates.InetSocketAddressTemplates;
import testing.templates.MessageTemplates;

import java.util.List;
import java.util.concurrent.Executor;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;

public class ResolverTemplates {
public static List<Resolver> googleDnsAsList() {
return List.of(new SimpleResolver(InetSocketAddressTemplates._8_8_8_8()));
}

@SneakyThrows
public static Resolver successAAcmeAnswer() {
final var resolver = new SimpleResolver();

doReturn(MessageTemplates.acmeAResponse())
.when(resolver)
.send(any());
;
doReturn(MessageTemplates.acmeAResponse())
.when(resolver)
.sendAsync(any())
;
doReturn(MessageTemplates.acmeAResponse())
.when(resolver)
.sendAsync(any(), any(Executor.class));
;
return resolver;
}
}
Loading