Created
December 3, 2014 15:16
-
-
Save benkamphaus/fa58a50ee02111a81487 to your computer and use it in GitHub Desktop.
Expected behavior for Datomic on peers during a transactor restart, in Java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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