-
Notifications
You must be signed in to change notification settings - Fork 420
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
Implement changes to client auto-test threading #4256
Changes from 2 commits
0cb7216
6a51771
70d06be
36a127f
08fbc86
644ef14
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 |
---|---|---|
|
@@ -23,11 +23,9 @@ | |
import java.nio.file.Paths; | ||
import java.time.Duration; | ||
import java.util.Objects; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.Function; | ||
|
||
import net.minecraft.server.Main; | ||
import net.minecraft.server.dedicated.MinecraftDedicatedServer; | ||
|
@@ -51,25 +49,14 @@ public String getConnectionAddress() { | |
} | ||
|
||
public void runCommand(String command) { | ||
submitAndWait(server -> { | ||
server.enqueueCommand(command, server.getCommandSource()); | ||
return null; | ||
}); | ||
ThreadingImpl.runOnServer(() -> server.getCommandManager().executeWithPrefix(server.getCommandSource(), command)); | ||
} | ||
|
||
private void run() { | ||
setupServer(); | ||
Main.main(new String[]{}); | ||
} | ||
|
||
private <T> CompletableFuture<T> submit(Function<MinecraftDedicatedServer, T> function) { | ||
return server.submit(() -> function.apply(server)); | ||
} | ||
|
||
private <T> T submitAndWait(Function<MinecraftDedicatedServer, T> function) { | ||
return submit(function).join(); | ||
} | ||
|
||
Comment on lines
-65
to
-72
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. Why are there no 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. They were private and unused so I deleted them, the equivalent is in 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. OK. |
||
private void setupServer() { | ||
try { | ||
Files.writeString(Paths.get("eula.txt"), "eula=true"); | ||
|
@@ -100,7 +87,12 @@ private void waitUntilReady() { | |
|
||
@Override | ||
public void close() { | ||
server.stop(true); | ||
server.stop(false); | ||
|
||
while (server.getThread().isAlive()) { | ||
ThreadingImpl.runTick(); | ||
} | ||
|
||
executor.close(); | ||
} | ||
} |
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.
Suggestion: Calling it
getFromClient()
instead ofcomputeOnClient()
would make it clearer that this method returns a value whilerunOnClient()
doesn't.Your use of
compute
here isn't wrong, I believe the Java API does something similar, but I think many people userun
andcompute
synonymously and wouldn't immediately grasp that this is the difference between them.get
vsrun
makes it really obvious.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.
I'm pretty sure this is the more common terminology, although I'm not super attached to it. But it should be immediately obvious what the difference between the two functions are from the parameter type
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.
I do like simple language, but yeah
compute
is pretty common too. I don't think parameter/return types are usually the first thing I would look at when working with a new API, but then again this will eventually have Javadoc that can make it obvious more quickly.