From 26fc81acadb27fc9eb7d1226fda58e5f4a67bf1b Mon Sep 17 00:00:00 2001 From: mikera Date: Tue, 18 Jun 2024 12:12:18 +0100 Subject: [PATCH] Merge branch 'develop' of https://github.com/Convex-Dev/convex.git into develop --- .../test/java/convex/actors/RegistryTest.java | 48 +++++----- .../convex/gui/tools/MessageFormatPanel.java | 1 + .../test/java/convex/restapi/StressTest.java | 91 ++++++++++--------- 3 files changed, 71 insertions(+), 69 deletions(-) diff --git a/convex-core/src/test/java/convex/actors/RegistryTest.java b/convex-core/src/test/java/convex/actors/RegistryTest.java index 8e79c040b..4fbb3f01f 100644 --- a/convex-core/src/test/java/convex/actors/RegistryTest.java +++ b/convex-core/src/test/java/convex/actors/RegistryTest.java @@ -32,7 +32,7 @@ protected RegistryTest() throws IOException { @Test public void testRegistryContract() throws IOException { - Context ctx =context(); + Context ctx = context(); AHashMap ddo = Maps.of(Keyword.create("name"), "Bob"); ctx = ctx.actorCall(REG, 0, Symbol.create("register"), ddo); @@ -41,67 +41,67 @@ public void testRegistryContract() throws IOException { @Test public void testRegistryCNS() throws IOException { - Context ctx=context(); + Context ctx = context(); - assertEquals(REG,eval(ctx,"(call *registry* (cns-resolve 'convex.registry))")); + assertEquals(REG, eval(ctx, "(call *registry* (cns-resolve 'convex.registry))")); } @Test public void testRegistryCNSUpdate() throws IOException { - Context ctx=context(); + Context ctx = context(); - assertNull(eval(ctx,"(call *registry* (cns-resolve 'convex.test.foo))")); + assertNull(eval(ctx, "(call *registry* (cns-resolve 'convex.test.foo))")); // Real Address we want for CNS mapping - final Address badAddr=Samples.BAD_ADDRESS; + final Address badAddr = Samples.BAD_ADDRESS; - ctx=step(ctx,"(call *registry* (cns-update 'convex.test.foo "+badAddr+"))"); + ctx = step(ctx, "(call *registry* (cns-update 'convex.test.foo " + badAddr + "))"); assertNobodyError(ctx); - + // Should fail, not a Symbol - ctx=step(ctx,"(call *registry* (cns-update \"convex.test.foo\" #1))"); + ctx = step(ctx, "(call *registry* (cns-update \"convex.test.foo\" #1))"); assertArgumentError(ctx); - final Address realAddr=Address.create(1); // Init address, FWIW - ctx=exec(ctx,"(call *registry* (cns-update 'convex.test.foo "+realAddr+"))"); + final Address realAddr = Address.create(1); // Init address, FWIW + ctx = exec(ctx, "(call *registry* (cns-update 'convex.test.foo " + realAddr + "))"); - assertEquals(realAddr,eval(ctx,"(call *registry* (cns-resolve 'convex.test.foo))")); + assertEquals(realAddr, eval(ctx, "(call *registry* (cns-resolve 'convex.test.foo))")); { // Check VILLAIN can't steal CNS mapping - Context c=ctx.forkWithAddress(VILLAIN); + Context c = ctx.forkWithAddress(VILLAIN); // VILLAIN shouldn't be able to use update on existing CNS mapping - assertTrustError(step(c,"(call *registry* (cns-update 'convex.test.foo *address*))")); + assertTrustError(step(c, "(call *registry* (cns-update 'convex.test.foo *address*))")); // original mapping should be held - assertEquals(realAddr,eval(c,"(call *registry* (cns-resolve 'convex.test.foo))")); + assertEquals(realAddr, eval(c, "(call *registry* (cns-resolve 'convex.test.foo))")); } { // Check Transfer of control to VILLAIN - Context c=exec(ctx,"(call *registry* (cns-control 'convex.test.foo "+VILLAIN+"))"); + Context c = exec(ctx, "(call *registry* (cns-control 'convex.test.foo " + VILLAIN + "))"); // HERO shouldn't be able to use update or control any more - assertTrustError(step(c,"(call *registry* (cns-update 'convex.test.foo *address*))")); - assertTrustError(step(c,"(call *registry* (cns-control 'convex.test.foo *address*))")); + assertTrustError(step(c, "(call *registry* (cns-update 'convex.test.foo *address*))")); + assertTrustError(step(c, "(call *registry* (cns-control 'convex.test.foo *address*))")); // Switch to VILLAIN - c=c.forkWithAddress(VILLAIN); + c = c.forkWithAddress(VILLAIN); // Change mapping - c=exec(c,"(call *registry* (cns-update 'convex.test.foo *address*))"); - assertEquals(VILLAIN,eval(c,"(call *registry* (cns-resolve 'convex.test.foo))")); + c = exec(c, "(call *registry* (cns-update 'convex.test.foo *address*))"); + assertEquals(VILLAIN, eval(c, "(call *registry* (cns-resolve 'convex.test.foo))")); } { // Check VILLAIN can create new mapping // TODO probably shouldn't be free-for-all? - Context c=ctx.forkWithAddress(VILLAIN); + Context c = ctx.forkWithAddress(VILLAIN); // VILLAIN shouldn't be able to use update on existing CNS mapping - c=exec(c,"(call *registry* (cns-update 'convex.villain *address*))"); + c = exec(c, "(call *registry* (cns-update 'convex.villain *address*))"); // original mapping should be held - assertEquals(VILLAIN,eval(c,"(call *registry* (cns-resolve 'convex.villain))")); + assertEquals(VILLAIN, eval(c, "(call *registry* (cns-resolve 'convex.villain))")); } } } diff --git a/convex-gui/src/main/java/convex/gui/tools/MessageFormatPanel.java b/convex-gui/src/main/java/convex/gui/tools/MessageFormatPanel.java index 7c410b4f2..29b72b0f2 100644 --- a/convex-gui/src/main/java/convex/gui/tools/MessageFormatPanel.java +++ b/convex-gui/src/main/java/convex/gui/tools/MessageFormatPanel.java @@ -137,6 +137,7 @@ private void updateData() { messageArea.setText(msg); } + @SuppressWarnings("null") private void updateHashLabel(ACell v, Blob b) { StringBuilder sb=new StringBuilder(); boolean empty=(b==null); diff --git a/convex-restapi/src/test/java/convex/restapi/StressTest.java b/convex-restapi/src/test/java/convex/restapi/StressTest.java index 100645132..dd8ecacea 100644 --- a/convex-restapi/src/test/java/convex/restapi/StressTest.java +++ b/convex-restapi/src/test/java/convex/restapi/StressTest.java @@ -20,82 +20,83 @@ public class StressTest { static RESTServer server; static int port; - static int CLIENTCOUNT=100; - static int TRANSCOUNT=100; - static AKeyPair KP=AKeyPair.generate(); - + static int CLIENTCOUNT = 100; + static int TRANSCOUNT = 100; + static AKeyPair KP = AKeyPair.generate(); + static { - Server s=API.launchPeer(); - RESTServer rs=RESTServer.create(s); + Server s = API.launchPeer(); + RESTServer rs = RESTServer.create(s); rs.start(0); - port=rs.getPort(); - server=rs; + port = rs.getPort(); + server = rs; } - + public static void main(String... args) throws InterruptedException, ExecutionException, TimeoutException { try { - Convex convex=Convex.connect("http://localhost:"+port); - long startTime=Utils.getTimeMillis(); - - ArrayList clients=new ArrayList<>(CLIENTCOUNT); - for (int i=0; i clients = new ArrayList<>(CLIENTCOUNT); + for (int i = 0; i < CLIENTCOUNT; i++) { + AKeyPair kp = KP; Address clientAddr = convex.createAccount(kp); - Convex cc=Convex.connect("http://localhost:"+port); + Convex cc = Convex.connect("http://localhost:" + port); cc.setAddress(clientAddr); cc.setKeyPair(kp); clients.add(cc); } - - long genTime=Utils.getTimeMillis(); - System.out.println(CLIENTCOUNT+ " REST clients connected in "+compTime(startTime,genTime)); - - ExecutorService ex=ThreadUtils.getVirtualExecutor(); - - ArrayList> cfutures=ThreadUtils.futureMap (ex,cc->{ + + long genTime = Utils.getTimeMillis(); + System.out.println(CLIENTCOUNT + " REST clients connected in " + compTime(startTime, genTime)); + + ExecutorService ex = ThreadUtils.getVirtualExecutor(); + + ArrayList> cfutures = ThreadUtils.futureMap(ex, cc -> { for (int i = 0; i < TRANSCOUNT; i++) { String source = "*timestamp*"; cc.query(source); } return null; - },clients); + }, clients); // wait for everything to be sent ThreadUtils.awaitAll(cfutures); - - long queryTime=Utils.getTimeMillis(); - System.out.println(CLIENTCOUNT * TRANSCOUNT+ " REST queries in "+compTime(queryTime,genTime)); - - cfutures=ThreadUtils.futureMap (ex,cc->{ + + long queryTime = Utils.getTimeMillis(); + System.out.println(CLIENTCOUNT * TRANSCOUNT + " REST queries in " + compTime(queryTime, genTime)); + + cfutures = ThreadUtils.futureMap(ex, cc -> { return cc.faucet(cc.getAddress(), 1000000); - },clients); + }, clients); // wait for everything to be sent ThreadUtils.awaitAll(cfutures); - - long faucetTime=Utils.getTimeMillis(); - System.out.println(CLIENTCOUNT+ " Faucet transactions completed in "+compTime(faucetTime,queryTime)); - - cfutures=ThreadUtils.futureMap (ex,cc->{ + + long faucetTime = Utils.getTimeMillis(); + System.out.println(CLIENTCOUNT + " Faucet transactions completed in " + compTime(faucetTime, queryTime)); + + cfutures = ThreadUtils.futureMap(ex, cc -> { // System.out.println(cc.queryAccount()); - Map res = cc.transact("(def a 1)"); - if (res.get("errorCode")!=null) throw new Error(JSON.toPrettyString(res)); + Map res = cc.transact("(def a 1)"); + if (res.get("errorCode") != null) + throw new Error(JSON.toPrettyString(res)); return res; - },clients); + }, clients); // wait for everything to be sent ThreadUtils.awaitAll(cfutures); - - long transTime=Utils.getTimeMillis(); - System.out.println(CLIENTCOUNT+ " transactions executed in "+compTime(faucetTime,transTime)); + + long transTime = Utils.getTimeMillis(); + System.out.println(CLIENTCOUNT + " transactions executed in " + compTime(faucetTime, transTime)); } catch (Throwable t) { t.printStackTrace(); - } finally { + } finally { System.exit(0); } - + } private static String compTime(long a, long b) { - long d=Math.abs(a-b); - return d+"ms"; + long d = Math.abs(a - b); + return d + "ms"; } }