Search in sources :

Example 26 with BinaryOutputArchive

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>());
}
Also used : BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) CreateRequest(org.apache.zookeeper.proto.CreateRequest) CreateRequest(org.apache.zookeeper.proto.CreateRequest) Request(org.apache.zookeeper.server.Request) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Id(org.apache.zookeeper.data.Id) ByteBuffer(java.nio.ByteBuffer)

Example 27 with BinaryOutputArchive

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>());
}
Also used : BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) GetDataRequest(org.apache.zookeeper.proto.GetDataRequest) CreateRequest(org.apache.zookeeper.proto.CreateRequest) SetDataRequest(org.apache.zookeeper.proto.SetDataRequest) Request(org.apache.zookeeper.server.Request) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Id(org.apache.zookeeper.data.Id) ByteBuffer(java.nio.ByteBuffer)

Example 28 with BinaryOutputArchive

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;
}
Also used : BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) InetSocketAddress(java.net.InetSocketAddress) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with BinaryOutputArchive

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);
    }
}
Also used : BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) ByteArrayInputStream(java.io.ByteArrayInputStream) EOFException(java.io.EOFException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket) Test(org.junit.jupiter.api.Test)

Example 30 with BinaryOutputArchive

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;
}
Also used : BinaryInputArchive(org.apache.jute.BinaryInputArchive) BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) ByteBufferInputStream(org.apache.zookeeper.server.ByteBufferInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer)

Aggregations

BinaryOutputArchive (org.apache.jute.BinaryOutputArchive)48 ByteArrayOutputStream (java.io.ByteArrayOutputStream)41 ByteBuffer (java.nio.ByteBuffer)18 Test (org.junit.jupiter.api.Test)16 BinaryInputArchive (org.apache.jute.BinaryInputArchive)12 CreateRequest (org.apache.zookeeper.proto.CreateRequest)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 IOException (java.io.IOException)10 TxnHeader (org.apache.zookeeper.txn.TxnHeader)10 Id (org.apache.zookeeper.data.Id)9 Record (org.apache.jute.Record)8 SetDataRequest (org.apache.zookeeper.proto.SetDataRequest)7 CreateTxn (org.apache.zookeeper.txn.CreateTxn)7 Request (org.apache.zookeeper.server.Request)6 ArrayList (java.util.ArrayList)5 DeleteTxn (org.apache.zookeeper.txn.DeleteTxn)5 MultiTxn (org.apache.zookeeper.txn.MultiTxn)5 Txn (org.apache.zookeeper.txn.Txn)5 BufferedOutputStream (java.io.BufferedOutputStream)4 File (java.io.File)4