use of org.apache.jute.BinaryOutputArchive in project zookeeper by apache.
the class SessionUpgradeQuorumTest method createEphemeralRequest.
private Request createEphemeralRequest(String path, long sessionId) throws IOException {
ByteArrayOutputStream boas = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
CreateRequest createRequest = new CreateRequest(path, "data".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL.toFlag());
createRequest.serialize(boa, "request");
ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
return new Request(null, sessionId, 1, ZooDefs.OpCode.create2, bb, new ArrayList<Id>());
}
use of org.apache.jute.BinaryOutputArchive in project zookeeper by apache.
the class CommitProcessorConcurrencyTest method newRequest.
private Request newRequest(Record rec, int type, int sessionId, int xid) throws IOException {
ByteArrayOutputStream boas = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
rec.serialize(boa, "request");
ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
return new Request(null, sessionId, xid, type, bb, new ArrayList<Id>());
}
use of org.apache.jute.BinaryOutputArchive in project zookeeper by apache.
the class LearnerHandlerMetricsTest method setup.
@BeforeEach
public void setup() throws IOException {
Leader leader = mock(Leader.class);
when(leader.getQuorumAuthServer()).thenReturn(null);
Socket socket = mock(Socket.class);
when(socket.getRemoteSocketAddress()).thenReturn(new InetSocketAddress(32));
// adding 5ms artificial delay when sending each packet
BinaryOutputArchive oa = mock(BinaryOutputArchive.class);
doAnswer(invocationOnMock -> {
Thread.sleep(5);
return null;
}).when(oa).writeRecord(any(QuorumPacket.class), anyString());
BufferedOutputStream bos = mock(BufferedOutputStream.class);
// flush is called when all packets are sent and the queue is empty
doAnswer(invocationOnMock -> {
if (allSentLatch != null) {
allSentLatch.countDown();
}
return null;
}).when(bos).flush();
learnerHandler = new MockLearnerHandler(socket, leader);
learnerHandler.setOutputArchive(oa);
learnerHandler.setBufferedOutput(bos);
learnerHandler.sid = sid;
}
use of org.apache.jute.BinaryOutputArchive in project zookeeper by apache.
the class LearnerTest method truncFailTest.
@Test
public void truncFailTest() throws Exception {
final boolean[] exitProcCalled = { false };
ServiceUtils.setSystemExitProcedure(new Consumer<Integer>() {
@Override
public void accept(Integer exitCode) {
exitProcCalled[0] = true;
assertThat("System.exit() was called with invalid exit code", exitCode, equalTo(ExitCode.QUORUM_PACKET_ERROR.getValue()));
}
});
File tmpFile = File.createTempFile("test", ".dir", testData);
tmpFile.delete();
try {
FileTxnSnapLog txnSnapLog = new FileTxnSnapLog(tmpFile, tmpFile);
SimpleLearner sl = new SimpleLearner(txnSnapLog);
long startZxid = sl.zk.getLastProcessedZxid();
// Set up bogus streams
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream());
// make streams and socket do something innocuous
sl.bufferedOutput = new BufferedOutputStream(System.out);
sl.sock = new Socket();
// fake messages from the server
QuorumPacket qp = new QuorumPacket(Leader.TRUNC, 0, null, null);
oa.writeRecord(qp, null);
// setup the messages to be streamed to follower
sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
try {
sl.syncWithLeader(3);
} catch (EOFException e) {
}
sl.zk.shutdown();
assertThat("System.exit() should have been called", exitProcCalled[0], is(true));
} finally {
TestUtils.deleteFileRecursively(tmpFile);
}
}
use of org.apache.jute.BinaryOutputArchive in project zookeeper by apache.
the class MultiOperationRecordTest method codeDecode.
private MultiOperationRecord codeDecode(MultiOperationRecord request) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
request.serialize(boa, "request");
baos.close();
ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
bb.rewind();
BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(bb));
MultiOperationRecord decodedRequest = new MultiOperationRecord();
decodedRequest.deserialize(bia, "request");
return decodedRequest;
}
Aggregations