use of com.arjuna.ats.arjuna.state.InputBuffer in project narayana by jbosstm.
the class HornetqJournalStore method start.
public void start() throws Exception {
journal.start();
List<RecordInfo> committedRecords = new LinkedList<RecordInfo>();
List<PreparedTransactionInfo> preparedTransactions = new LinkedList<PreparedTransactionInfo>();
TransactionFailureCallback failureCallback = new TransactionFailureCallback() {
public void failedTransaction(long l, List<RecordInfo> recordInfos, List<RecordInfo> recordInfos1) {
tsLogger.i18NLogger.warn_journal_load_error();
}
};
JournalLoadInformation journalLoadInformation = journal.load(committedRecords, preparedTransactions, failureCallback);
maxID.set(journalLoadInformation.getMaxID());
if (!preparedTransactions.isEmpty()) {
tsLogger.i18NLogger.warn_journal_load_error();
}
for (RecordInfo record : committedRecords) {
InputBuffer inputBuffer = new InputBuffer(record.data);
Uid uid = UidHelper.unpackFrom(inputBuffer);
String typeName = inputBuffer.unpackString();
getContentForType(typeName).put(uid, record);
// don't unpack the rest yet, we may never need it. read_committed does it on demand.
}
}
use of com.arjuna.ats.arjuna.state.InputBuffer in project narayana by jbosstm.
the class IOStateUnitTest method testIOObjectState.
@Test
public void testIOObjectState() throws Exception {
OutputObjectState oos = new OutputObjectState(new Uid(), "");
oos.packBoolean(true);
oos.packByte((byte) 0);
oos.packChar('a');
oos.packDouble(1.0);
oos.packFloat((float) 1.0);
oos.packInt(1);
oos.packLong(1234);
oos.packShort((short) 10);
oos.packString("test");
assertTrue(oos.valid());
PrintWriter pw = new PrintWriter(new StringWriter());
oos.print(pw);
assertTrue(oos.length() != 0);
assertTrue(oos.notempty());
assertTrue(oos.stateUid() != Uid.nullUid());
assertTrue(oos.buffer() != null);
assertTrue(oos.size() > 0);
assertTrue(oos.type() != null);
OutputObjectState temp = new OutputObjectState(oos);
assertTrue(temp.toString() != null);
InputObjectState ios = new InputObjectState(oos);
assertTrue(ios.buffer() != null);
assertTrue(ios.length() > 0);
assertTrue(ios.notempty());
assertTrue(ios.size() > 0);
assertTrue(ios.stateUid() != Uid.nullUid());
assertTrue(ios.valid());
ios.print(pw);
InputObjectState is = new InputObjectState(ios);
assertTrue(is.toString() != null);
assertTrue(ios.unpackBoolean());
assertEquals(ios.unpackByte(), (byte) 0);
assertEquals(ios.unpackChar(), 'a');
assertTrue(ios.unpackDouble() == 1.0);
assertTrue(ios.unpackFloat() == (float) 1.0);
assertEquals(ios.unpackInt(), 1);
assertEquals(ios.unpackLong(), 1234);
assertEquals(ios.unpackShort(), (short) 10);
assertEquals(ios.unpackString(), "test");
InputObjectState c = new InputObjectState();
OutputObjectState buff = new OutputObjectState();
OutputObjectState o = new OutputObjectState();
Uid u = new Uid();
buff.packString("foobar");
UidHelper.packInto(u, buff);
buff.packInto(o);
InputBuffer ibuff = new InputBuffer(o.buffer());
c.copy(ios);
ios.unpackFrom(ibuff);
ios.copyFrom(new OutputObjectState());
assertTrue(ios.toString() != null);
oos.reset();
oos.rewrite();
oos.packInto(new OutputObjectState());
oos.copy(new OutputObjectState());
assertTrue(oos.toString() != null);
temp = new OutputObjectState(new Uid(), "", null);
assertFalse(temp.valid());
}
use of com.arjuna.ats.arjuna.state.InputBuffer in project narayana by jbosstm.
the class HornetqJournalStore method read_committed.
/**
* Read the object's committed state.
*
* @param uid The object to work on.
* @param typeName The type of the object to work on.
* @return the state of the object.
* @throws ObjectStoreException if things go wrong.
*/
public InputObjectState read_committed(Uid uid, String typeName) throws ObjectStoreException {
RecordInfo record = getContentForType(typeName).get(uid);
if (record == null) {
return null;
}
// not too much of an issue as log reads are done for recovery only.
try {
InputBuffer inputBuffer = new InputBuffer(record.data);
UidHelper.unpackFrom(inputBuffer);
inputBuffer.unpackString();
return new InputObjectState(uid, typeName, inputBuffer.unpackBytes());
} catch (Exception e) {
throw new ObjectStoreException(e);
}
}
use of com.arjuna.ats.arjuna.state.InputBuffer in project narayana by jbosstm.
the class ActionHierarchyUnitTest method test.
@Test
public void test() throws Exception {
ActionHierarchy ah = new ActionHierarchy(5);
Uid[] tx = new Uid[5];
assertEquals(ah.getDeepestActionUid(), Uid.nullUid());
for (int i = 0; i < tx.length; i++) {
tx[i] = new Uid();
ah.add(tx[i]);
}
assertEquals(ah.depth(), tx.length);
assertEquals(ah.getActionUid(0), tx[0]);
Uid deepest = new Uid();
ah.add(deepest, ActionType.TOP_LEVEL);
PrintWriter pw = new PrintWriter(System.err);
ah.print(pw);
assertEquals(ah.getDeepestActionUid(), deepest);
ActionHierarchy cp = new ActionHierarchy(ah);
assertTrue(cp.equals(ah));
cp.copy(ah);
ah.copy(ah);
assertTrue(cp.equals(ah));
OutputBuffer out = new OutputBuffer();
cp.pack(out);
InputBuffer in = new InputBuffer(out.buffer());
ah.unpack(in);
assertTrue(ah.equals(cp));
assertTrue(ah.isAncestor(deepest));
ah.forgetDeepest();
assertTrue(ah.findCommonPrefix(cp) != 0);
}
use of com.arjuna.ats.arjuna.state.InputBuffer in project narayana by jbosstm.
the class IOStateUnitTest method testIOObjectBuffer.
@Test
public void testIOObjectBuffer() throws Exception {
PrintWriter pw = new PrintWriter(new StringWriter());
OutputBuffer obuff = new OutputBuffer(1024);
obuff.print(pw);
assertTrue(obuff.toString() != null);
OutputBuffer tobuff = new OutputBuffer(obuff);
assertTrue(tobuff.valid());
InputBuffer ibuff = new InputBuffer();
ibuff.print(pw);
InputBuffer tibuff = new InputBuffer(ibuff);
assertEquals(tibuff.valid(), false);
}
Aggregations