TPCLog { public void appendAndFlush(KVMessage entry) { entries.add(entry); flushToDisk(); } TPCLog(String logPath, KVServer kvServer); ArrayList<KVMessage> getEntries(); boolean empty(); void appendAndFlush(KVMessage entry); @SuppressWarnings("unchecked") void loadFromDisk(); void flushToDisk(); KVServer getKvServer(); void setKvServer(KVServer kvServer); void rebuildKeyServer(); KVMessage getInterruptedTpcOperation(); boolean hasInterruptedTpcOperation(); public String logPath; public KVServer kvServer; public ArrayList<KVMessage> entries; public KVMessage interruptedTpcOperation; }
@Test public void test() throws Exception { KVServer s = new KVServer(100, 100); TPCLog log = new TPCLog("test", s); KVMessage x = new KVMessage("putreq"); x.setKey("hello"); x.setValue("bye bye"); log.appendAndFlush(x); s.put("hello", "bye bye"); ObjectInputStream f = new ObjectInputStream(new FileInputStream("test")); ArrayList<KVMessage> garbage = (ArrayList<KVMessage>) f.readObject(); KVMessage mess = garbage.get(0); assertEquals(mess.getKey(), "hello"); assertEquals(mess.getValue(), "bye bye"); }