This is an automated email from the ASF dual-hosted git repository.

dcapwell pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-accord.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 119ed54  CEP-15 (Accord): Add CircleCI configs to build the project 
(#8)
119ed54 is described below

commit 119ed545c2532c830d8dcb682741f0f8819a6c30
Author: dcapwell <[email protected]>
AuthorDate: Thu Aug 4 13:25:03 2022 -0700

    CEP-15 (Accord): Add CircleCI configs to build the project (#8)
    
    
    patch by David Capwell; reviewed by Benedict Elliott Smith for 
CASSANDRA-17796
---
 .circleci/config.yml                               | 74 ++++++++++++++++++++++
 .../main/java/accord/impl/SimpleProgressLog.java   |  4 +-
 .../src/main/java/accord/maelstrom/Body.java       |  3 +-
 .../src/main/java/accord/maelstrom/Cluster.java    |  9 ++-
 .../src/main/java/accord/maelstrom/Packet.java     | 69 +++++++++++++-------
 5 files changed, 131 insertions(+), 28 deletions(-)

diff --git a/.circleci/config.yml b/.circleci/config.yml
new file mode 100644
index 0000000..094d8b7
--- /dev/null
+++ b/.circleci/config.yml
@@ -0,0 +1,74 @@
+# Java Gradle CircleCI 2.0 configuration file
+# See: https://circleci.com/docs/2.0/language-java/
+version: 2
+
+# Define a job to be invoked later in a workflow.
+# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
+jobs:
+  build:
+    # Specify the execution environment. You can specify an image from 
Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
+    # See: 
https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
+    docker:
+      # specify the version you desire here
+      - image: cimg/openjdk:11.0
+    resource_class: medium
+    working_directory: ~/repo
+
+    environment:
+      # Customize the JVM maximum heap limit
+      JVM_OPTS: -Xmx3200m
+      TERM: dumb
+    # Add steps to the job
+    # See: https://circleci.com/docs/2.0/configuration-reference/#steps
+    steps:
+      - checkout
+
+      # Download and cache dependencies
+      - restore_cache:
+          keys:
+            - v1-dependencies-{{ checksum "build.gradle" }}-{{ checksum 
"accord-core/build.gradle" }}-{{ checksum "accord-maelstrom/build.gradle" }}-{{ 
checksum "gradle/wrapper/gradle-wrapper.properties" }}
+            # fallback to using the latest cache if no exact match is found
+            - v1-dependencies-
+
+      - run:
+          name: Log Environment Information
+          command: |
+            echo '*** id ***'
+            id
+            echo '*** cat /proc/cpuinfo ***'
+            cat /proc/cpuinfo
+            echo '*** free -m ***'
+            free -m
+            echo '*** df -m ***'
+            df -m
+            echo '*** ifconfig -a ***'
+            ifconfig -a
+            echo '*** uname -a ***'
+            uname -a
+            echo '*** mount ***'
+            mount
+            echo '*** env ***'
+            env
+            echo '*** java ***'
+            which java
+            java -version 2>&1
+            echo '*** gradle ***'
+            ./gradlew --version
+
+      - run: ./gradlew dependencies
+
+      - save_cache:
+          paths:
+            - ~/.gradle
+          key: v1-dependencies-{{ checksum "build.gradle" }}-{{ checksum 
"accord-core/build.gradle" }}-{{ checksum "accord-maelstrom/build.gradle" }}-{{ 
checksum "gradle/wrapper/gradle-wrapper.properties" }}
+
+      # run tests!
+      - run: ./gradlew test
+      - run:
+          name: Save Test Results
+          command: |
+            mkdir test-results
+            find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} 
test-results \;
+          when: always
+      - store_test_results:
+          path: test-results
diff --git a/accord-core/src/main/java/accord/impl/SimpleProgressLog.java 
b/accord-core/src/main/java/accord/impl/SimpleProgressLog.java
index a8fe419..00bf967 100644
--- a/accord-core/src/main/java/accord/impl/SimpleProgressLog.java
+++ b/accord-core/src/main/java/accord/impl/SimpleProgressLog.java
@@ -776,7 +776,7 @@ public class SimpleProgressLog implements Runnable, 
ProgressLog.Factory
         }
     }
 
-    static class ApplyAndCheck extends Apply
+    public static class ApplyAndCheck extends Apply
     {
         final Set<Id> notPersisted;
         ApplyAndCheck(Id id, Topologies topologies, TxnId txnId, Txn txn, Key 
homeKey, Dependencies deps, Timestamp executeAt, Writes writes, Result result, 
Set<Id> notPersisted)
@@ -833,7 +833,7 @@ public class SimpleProgressLog implements Runnable, 
ProgressLog.Factory
         }
     }
 
-    static class ApplyAndCheckOk implements Reply
+    public static class ApplyAndCheckOk implements Reply
     {
         final Set<Id> notPersisted;
 
diff --git a/accord-maelstrom/src/main/java/accord/maelstrom/Body.java 
b/accord-maelstrom/src/main/java/accord/maelstrom/Body.java
index 651fc68..7d08377 100644
--- a/accord-maelstrom/src/main/java/accord/maelstrom/Body.java
+++ b/accord-maelstrom/src/main/java/accord/maelstrom/Body.java
@@ -4,6 +4,7 @@ import java.io.IOException;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 import com.google.gson.JsonArray;
 import com.google.gson.TypeAdapter;
@@ -23,7 +24,7 @@ public class Body
 
     public Body(Type type, long msg_id, long in_reply_to)
     {
-        this.type = type;
+        this.type = Objects.requireNonNull(type);
         this.msg_id = msg_id;
         this.in_reply_to = in_reply_to;
     }
diff --git a/accord-maelstrom/src/main/java/accord/maelstrom/Cluster.java 
b/accord-maelstrom/src/main/java/accord/maelstrom/Cluster.java
index 97609a6..10be41e 100644
--- a/accord-maelstrom/src/main/java/accord/maelstrom/Cluster.java
+++ b/accord-maelstrom/src/main/java/accord/maelstrom/Cluster.java
@@ -163,15 +163,18 @@ public class Cluster implements Scheduler
                     }
                     err.println(clock++ + " RECV " + deliver);
                     err.flush();
-                    if (deliver.body.in_reply_to > Body.SENTINEL_MSG_ID)
+                    Object body = ((Wrapper)deliver.body).body;
+                    // for some reason InformOfTxnReply has 
deliver.body.in_reply_to == Body.SENTINEL_MSG_ID, so is unique
+                    // for all reply types
+                    if (deliver.body.in_reply_to > Body.SENTINEL_MSG_ID || 
body instanceof Reply)
                     {
-                        Reply reply = (Reply)((Wrapper)deliver.body).body;
+                        Reply reply = (Reply) body;
                         Callback callback = reply.isFinal() ? 
sinks.get(deliver.dest).callbacks.remove(deliver.body.in_reply_to)
                                                             : 
sinks.get(deliver.dest).callbacks.get(deliver.body.in_reply_to);
                         if (callback != null)
                             on.scheduler().now(() -> 
callback.onSuccess(deliver.src, reply));
                     }
-                    else on.receive((Request)((Wrapper)deliver.body).body, 
deliver.src, deliver);
+                    else on.receive((Request) body, deliver.src, deliver);
             }
         }
         else
diff --git a/accord-maelstrom/src/main/java/accord/maelstrom/Packet.java 
b/accord-maelstrom/src/main/java/accord/maelstrom/Packet.java
index 4b08864..752ff65 100644
--- a/accord-maelstrom/src/main/java/accord/maelstrom/Packet.java
+++ b/accord-maelstrom/src/main/java/accord/maelstrom/Packet.java
@@ -7,6 +7,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.function.Function;
 
+import accord.impl.SimpleProgressLog;
 import accord.messages.*;
 import com.google.gson.JsonObject;
 import com.google.gson.TypeAdapter;
@@ -16,6 +17,7 @@ import accord.local.Node.Id;
 
 public class Packet implements ReplyContext
 {
+
     public enum Type
     {
         init(MaelstromInit.class, MaelstromInit.GSON_ADAPTER),
@@ -23,26 +25,36 @@ public class Packet implements ReplyContext
         txn(MaelstromRequest.class, MaelstromRequest.GSON_ADAPTER),
         txn_ok(MaelstromReply.class, MaelstromReply.GSON_ADAPTER),
         error(Error.class, Error.GSON_ADAPTER),
-        PreAccept(accord.messages.PreAccept.class, Json.DEFAULT_ADAPTER),
-        PreAcceptOk(accord.messages.PreAccept.PreAcceptOk.class, 
Json.DEFAULT_ADAPTER),
-        PreAcceptNack(accord.messages.PreAccept.PreAcceptNack.class, 
Json.DEFAULT_ADAPTER),
-        Accept(accord.messages.Accept.class, Json.DEFAULT_ADAPTER),
-        AcceptOk(accord.messages.Accept.AcceptOk.class, Json.DEFAULT_ADAPTER),
-        AcceptNack(accord.messages.Accept.AcceptNack.class, 
Json.DEFAULT_ADAPTER),
-        Commit(accord.messages.Commit.class, Json.DEFAULT_ADAPTER),
-        Apply(Apply.class, Json.DEFAULT_ADAPTER),
-        Read(ReadData.class, Json.DEFAULT_ADAPTER),
-        ReadOk(ReadData.ReadOk.class, Json.DEFAULT_ADAPTER),
-        ReadNack(ReadData.ReadNack.class, Json.DEFAULT_ADAPTER),
-        WaitOnCommit(accord.messages.WaitOnCommit.class, Json.DEFAULT_ADAPTER),
-        WaitOnCommitOk(accord.messages.WaitOnCommit.WaitOnCommitOk.class, 
Json.DEFAULT_ADAPTER),
-        Recover(BeginRecovery.class, Json.DEFAULT_ADAPTER),
-        RecoverOk(BeginRecovery.RecoverOk.class, Json.DEFAULT_ADAPTER),
-        RecoverNack(BeginRecovery.RecoverNack.class, Json.DEFAULT_ADAPTER);
-
-        public static final Function<Class<?>, Type> LOOKUP = 
Arrays.stream(Type.values())
-                                                                    .filter(t 
-> t.type != null)
-                                                                    
.<Map<Class<?>, Type>>collect(HashMap::new, (m, t) -> m.put(t.type, t), 
Map::putAll)::get;
+        PreAccept(accord.messages.PreAccept.class),
+        PreAcceptOk(accord.messages.PreAccept.PreAcceptOk.class),
+        PreAcceptNack(accord.messages.PreAccept.PreAcceptNack.class),
+        Accept(accord.messages.Accept.class),
+        AcceptOk(accord.messages.Accept.AcceptOk.class),
+        AcceptNack(accord.messages.Accept.AcceptNack.class),
+        Commit(accord.messages.Commit.class),
+        Apply(Apply.class),
+        ApplyOk(Apply.ApplyOk.class),
+        Read(ReadData.class),
+        ReadOk(ReadData.ReadOk.class),
+        ReadNack(ReadData.ReadNack.class),
+        WaitOnCommit(accord.messages.WaitOnCommit.class),
+        WaitOnCommitOk(accord.messages.WaitOnCommit.WaitOnCommitOk.class),
+        Recover(BeginRecovery.class),
+        RecoverOk(BeginRecovery.RecoverOk.class),
+        RecoverNack(BeginRecovery.RecoverNack.class),
+        CheckStatus(CheckStatus.class),
+        CheckStatusOk(CheckStatus.CheckStatusOk.class),
+        CheckStatusOkFull(CheckStatus.CheckStatusOkFull.class),
+        InformOfTxn(InformOfTxn.class),
+        InformOfTxnOk(InformOfTxn.InformOfTxnOk.class),
+        InformOfPersistence(InformOfPersistence.class),
+        SimpleProgressLog_ApplyAndCheck(SimpleProgressLog.ApplyAndCheck.class),
+        
SimpleProgressLog_ApplyAndCheckOk(SimpleProgressLog.ApplyAndCheckOk.class);
+
+        private static final Map<Class<?>, Type> LOOKUP_MAP = 
Arrays.stream(Type.values())
+                .filter(t -> t.type != null)
+                .<Map<Class<?>, Type>>collect(HashMap::new, (m, t) -> 
m.put(t.type, t), Map::putAll);
+
         public final Class<?> type;
         public final TypeAdapter<?> adapter;
 
@@ -51,6 +63,19 @@ public class Packet implements ReplyContext
             this.type = type;
             this.adapter = adapter;
         }
+
+        Type(Class<?> type)
+        {
+            this(type, Json.DEFAULT_ADAPTER);
+        }
+
+        public static Type lookup(Class<?> klass)
+        {
+            Type value = LOOKUP_MAP.get(klass);
+            if (value == null)
+                throw new NullPointerException("Unable to lookup for class " + 
klass);
+            return value;
+        }
     }
 
     final Id src;
@@ -68,14 +93,14 @@ public class Packet implements ReplyContext
     {
         this.src = src;
         this.dest = dest;
-        this.body = new Wrapper(Type.LOOKUP.apply(body.getClass()), messageId, 
Body.SENTINEL_MSG_ID, body);
+        this.body = new Wrapper(Type.lookup(body.getClass()), messageId, 
Body.SENTINEL_MSG_ID, body);
     }
 
     public Packet(Id src, Id dest, long replyId, Reply body)
     {
         this.src = src;
         this.dest = dest;
-        this.body = body instanceof Body ? (Body) body : new 
Wrapper(Type.LOOKUP.apply(body.getClass()), Body.SENTINEL_MSG_ID, replyId, 
body);
+        this.body = body instanceof Body ? (Body) body : new 
Wrapper(Type.lookup(body.getClass()), Body.SENTINEL_MSG_ID, replyId, body);
     }
 
     public static Packet parse(String str)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to