zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yang <teddyyyy...@gmail.com>
Subject help with bookkeeper code?
Date Tue, 06 Sep 2011 05:02:24 GMT
I was trying to learn how to use BookKeeper, so I started from the test code
BookieClientTest.java, and stripped it down to the
most basic form (code pasted below),

now I just have the readEntry callback print out onto screen, but it doesn't
seem to be executed. there is not much doc available,
where am I doing wrong?

I setup my separate bookie server as instructed by the README.txt , by
java -cp
org.apache.bookkeeper.util.LocalBookKeeper 1

Thanks a lot

package org.apache.bookkeeper.test;

 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *   http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.

import java.io.File;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.Executors;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.socket.ClientSocketChannelFactory;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.junit.Test;
import org.apache.bookkeeper.client.BKException;
import org.apache.bookkeeper.proto.BookieClient;
import org.apache.bookkeeper.proto.BookieServer;
import org.apache.bookkeeper.util.OrderedSafeExecutor;
import org.apache.log4j.Logger;

import junit.framework.TestCase;

public class SimpleClientTest extends TestCase {
    static Logger LOG = Logger.getLogger(SimpleClientTest.class);
    BookieServer bs;
    File tmpDir;
    int port = 5000;
    ClientSocketChannelFactory channelFactory;
    OrderedSafeExecutor executor;

    protected void setUp() throws Exception {

        channelFactory = new
NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors
        executor = new OrderedSafeExecutor(2);

    ReadEntryCallback recb = new ReadEntryCallback() {

        public void readEntryComplete(int rc, long ledgerId, long entryId,
ChannelBuffer bb, Object ctx) {
            System.out.println("read something" + ledgerId + " " + entryId +
" " + bb);


    WriteCallback wrcb = new WriteCallback() {
        public void writeComplete(int rc, long ledgerId, long entryId,
InetSocketAddress addr, Object ctx) {
            if (ctx != null) {
                synchronized (ctx) {

    public void testWriteGaps() throws Exception {
        byte[] passwd = new byte[20];
        Arrays.fill(passwd, (byte) 'a');
        InetSocketAddress addr = new InetSocketAddress("", port);

        BookieClient bc = new BookieClient(channelFactory, executor);
        ChannelBuffer bb;
        bb = createByteBuffer(1, 1, 1);
        bc.addEntry(addr, 1, passwd, 1, bb, wrcb, null);
            bc.readEntry(addr, 1, 1, recb, null);


    private ChannelBuffer createByteBuffer(int i, long lid, long eid) {
        ByteBuffer bb;
        bb = ByteBuffer.allocate(4 + 16);
        return ChannelBuffers.wrappedBuffer(bb);

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message