Skip to content

Instantly share code, notes, and snippets.

@benkamphaus
Created December 3, 2014 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benkamphaus/fa58a50ee02111a81487 to your computer and use it in GitHub Desktop.
Save benkamphaus/fa58a50ee02111a81487 to your computer and use it in GitHub Desktop.
Expected behavior for Datomic on peers during a transactor restart, in Java.
/**
* Expected behavior during transactor shutdown and restart.
* */
import datomic.Connection;
import datomic.Peer;
import datomic.Database;
import datomic.Util;
import java.util.Scanner;
import java.util.List;
public class TransactorRestart {
public static void main(String[] args) throws InterruptedException {
String myUri = "datomic:free://localhost:4334/scratch";
Connection conn = Peer.connect(myUri);
// getting db from initial live state works
Database mydb = conn.db();
pause("Shut down transactor, then press <enter> to continue.");
// while transactor is shut down
System.out.println("Database from connection still works.");
Database mydb2 = conn.db();
System.out.println("Transaction fails.");
List datom = Util.list("db/add", Peer.tempid("db.part/user"),
"db/doc", "hello world");
try {
Object txResult = conn.transact(Util.list(datom));
} catch (clojure.lang.ExceptionInfo e) {
System.out.println("Transaction exception:" + e.getMessage());
}
// after connection re-established
pause("Restart transactor, verify connection is re-established by tailing logs, or wait > 30 seconds.");
System.out.println("We can get a db.");
Database mydb3 = conn.db();
System.out.println("We can now transact again.");
try {
Object txResult = conn.transact(Util.list(datom));
} catch (clojure.lang.ExceptionInfo e) {
System.out.println("Transaction exception:" + e.getMessage());
}
}
private static final Scanner scanner = new Scanner(System.in);
private static void pause(String prompt) {
System.out.println(prompt);
scanner.nextLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment