use of org.apache.jute.BinaryInputArchive in project zookeeper by apache.
the class LoadFromLogNoServerTest method testPad.
/**
* Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
* fixes it.
*/
@Test
public void testPad() throws Exception {
File tmpDir = ClientBase.createTmpDir();
FileTxnLog txnLog = new FileTxnLog(tmpDir);
TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123, Time.currentElapsedTime(), ZooDefs.OpCode.create);
Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
txnLog.append(txnHeader, txn);
FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." + Long.toHexString(txnHeader.getZxid()));
BinaryInputArchive ia = BinaryInputArchive.getArchive(in);
FileHeader header = new FileHeader();
header.deserialize(ia, "fileheader");
LOG.info("Received magic : {} Expected : {}", header.getMagic(), FileTxnLog.TXNLOG_MAGIC);
assertTrue(header.getMagic() == FileTxnLog.TXNLOG_MAGIC, "Missing magic number ");
}
use of org.apache.jute.BinaryInputArchive in project zookeeper by apache.
the class ClientCnxnSocket method readConnectResult.
void readConnectResult() throws IOException {
if (LOG.isTraceEnabled()) {
StringBuilder buf = new StringBuilder("0x[");
for (byte b : incomingBuffer.array()) {
buf.append(Integer.toHexString(b)).append(",");
}
buf.append("]");
if (LOG.isTraceEnabled()) {
LOG.trace("readConnectResult {} {}", incomingBuffer.remaining(), buf.toString());
}
}
ByteBufferInputStream bbis = new ByteBufferInputStream(incomingBuffer);
BinaryInputArchive bbia = BinaryInputArchive.getArchive(bbis);
ConnectResponse conRsp = new ConnectResponse();
conRsp.deserialize(bbia, "connect");
// read "is read-only" flag
boolean isRO = false;
try {
isRO = bbia.readBool("readOnly");
} catch (IOException e) {
// this is ok -- just a packet from an old server which
// doesn't contain readOnly field
LOG.warn("Connected to an old server; r-o mode will be unavailable");
}
this.sessionId = conRsp.getSessionId();
sendThread.onConnected(conRsp.getTimeOut(), this.sessionId, conRsp.getPasswd(), isRO);
}
use of org.apache.jute.BinaryInputArchive in project zookeeper by apache.
the class SaslQuorumAuthLearner method receive.
private QuorumAuthPacket receive(DataInputStream din) throws IOException {
QuorumAuthPacket authPacket = new QuorumAuthPacket();
BinaryInputArchive bia = BinaryInputArchive.getArchive(din);
authPacket.deserialize(bia, QuorumAuth.QUORUM_AUTH_MESSAGE_TAG);
return authPacket;
}
use of org.apache.jute.BinaryInputArchive in project zookeeper by apache.
the class QuorumAuth method nextPacketIsAuth.
public static boolean nextPacketIsAuth(DataInputStream din) throws IOException {
din.mark(32);
BinaryInputArchive bia = new BinaryInputArchive(din);
boolean firstIsAuth = (bia.readLong("NO_TAG") == QuorumAuth.QUORUM_AUTH_MAGIC_NUMBER);
din.reset();
return firstIsAuth;
}
use of org.apache.jute.BinaryInputArchive in project zookeeper by apache.
the class TxnLogSource method isTransactionFile.
public static boolean isTransactionFile(String file) throws IOException {
RandomAccessFileReader reader = new RandomAccessFileReader(new File(file));
BinaryInputArchive logStream = new BinaryInputArchive(reader);
FileHeader fhdr = new FileHeader();
fhdr.deserialize(logStream, "fileheader");
reader.close();
return fhdr.getMagic() == FileTxnLog.TXNLOG_MAGIC;
}
Aggregations