@Test(expected = NullPointerException.class)
 public void testAddNull() throws Exception {
   RetainLinkedList<String> list = new RetainLinkedList<String>(3);
   Field field = FieldUtil.getField(RetainLinkedList.class, "tail");
   FieldUtil.setFieldValue(list, field, null);
   list.add("hello");
 }
 @Test
 public void testAddNew() throws Exception {
   RpcStub handler = makeHandler();
   MultiplexPoolHandler han = new MultiplexPoolHandler(Collections.singleton(handler), 2, 3);
   han.setWaitTimeout(1);
   travelPool(han);
   ArrayList<RpcStub> list = new ArrayList<RpcStub>();
   list.add(makeHandler());
   list.add(makeHandler());
   list.add(makeHandler());
   han.addNew(list);
   travelPool(han);
   ArrayList<RpcStub> backupHandlers = FieldUtil.getValue(han, "backupHandlers");
   assertEquals(4, backupHandlers.size());
   LinkedBlockingQueue<RpcStub> readyQueue = FieldUtil.getValue(han, "readyQueue");
   assertEquals(4, readyQueue.size());
   RpcStub h1 = han.take();
   RpcStub h2 = han.take();
   RpcStub h3 = han.take();
   RpcStub h4 = han.take();
   travelPool(han);
   han.offer(h1);
   han.offer(h2);
   han.offer(h3);
   han.offer(h4);
   travelPool(han);
   ArrayList<RpcStub> list2 = new ArrayList<RpcStub>();
   list2.add(makeHandler());
   han.addNew(list2);
   assertEquals(5, backupHandlers.size());
   assertEquals(10, readyQueue.size());
   han.destroy();
 }
 /**
  * Test method for {@link org.apache.niolex.commons.collection.RetainLinkedList#handleRetain()}.
  */
 @Test(expected = NullPointerException.class)
 public void testHandleRetainCover() throws Exception {
   RetainLinkedList<String> list = new RetainLinkedList<String>(3);
   Field field = FieldUtil.getField(RetainLinkedList.class, "headPointerSize");
   FieldUtil.setFieldValue(list, field, 2);
   list.handleRetain();
 }
 /** @throws java.lang.Exception */
 @Before
 public void setUp() throws Exception {
   pool = new TestPool(mutableOne);
   FieldUtil.setValue(pool, "isWorking", true);
   ArrayList<RpcStub> empty = new ArrayList<RpcStub>();
   FieldUtil.setValue(pool, "poolHandler", new MultiplexPoolHandler(empty, 2, 2));
   readySet = FieldUtil.getValue(pool, "readySet");
 }
 @Test
 public void testBuildClients() throws Exception {
   FieldUtil.setValue(pool, "isWorking", false);
   FieldUtil.setValue(pool, "poolSize", 0);
   mutableOne.updateData(makeAddress());
   pool.build();
   pool.build(); // Already true
 }
 @Test
 public void testAddMultiplex() throws Exception {
   RpcStub handler = makeHandler(0);
   MultiplexPoolHandler han = new MultiplexPoolHandler(Collections.singleton(handler), 2, 3);
   han.addMultiplex(); // 2
   han.addMultiplex(); // 3
   han.addMultiplex(); // 3, return immediately
   Integer currentMultiplex = FieldUtil.getValue(han, "currentMultiplex");
   assertEquals(3, currentMultiplex.intValue());
   LinkedBlockingQueue<RpcStub> readyQueue = FieldUtil.getValue(han, "readyQueue");
   assertEquals(1, readyQueue.size());
 }
 @Test
 public void testSimplePool() throws Exception {
   FieldUtil.setValue(pool, "isWorking", false);
   mutableOne.updateData(makeAddress());
   pool.build();
   pool.build(); // Already true
 }
 /** Test method for {@link org.apache.niolex.commons.collection.RetainLinkedList#handleNext()}. */
 @Test(expected = NullPointerException.class)
 public void testHandleNextCover() throws Exception {
   RetainLinkedList<String> other = new RetainLinkedList<String>(3);
   other.add("It ");
   other.add("is ");
   other.add("a ");
   other.add("big ");
   other.add("world!");
   RetainLinkedList<String> list = new RetainLinkedList<String>(3);
   Field field = FieldUtil.getField(RetainLinkedList.class, "headPointerSize");
   FieldUtil.setFieldValue(list, field, 5);
   // ---
   field = FieldUtil.getField(RetainLinkedList.class, "pointer");
   Object ppt = FieldUtil.getFieldValue(other, field);
   FieldUtil.setFieldValue(list, field, ppt);
   list.handleNext();
 }
 @Test
 public void testDestroy() throws Exception {
   ArrayList<RpcStub> list = new ArrayList<RpcStub>();
   list.add(makeHandler2());
   list.add(makeHandler2());
   list.add(makeHandler2());
   MultiplexPoolHandler han = new MultiplexPoolHandler(list, 2, 3);
   han.setWaitTimeout(1);
   LinkedBlockingQueue<RpcStub> readyQueue = FieldUtil.getValue(han, "readyQueue");
   ArrayList<RpcStub> backupHandlers = FieldUtil.getValue(han, "backupHandlers");
   travelPool(han);
   han.destroy();
   travelPool(han);
   assertNull(han.take());
   assertNull(han.take());
   assertEquals(3, backupHandlers.size());
   assertEquals(0, readyQueue.size());
 }
示例#10
0
 @Test
 public void testMarkDeleted() throws Exception {
   List<String> data = makeAddress();
   FieldUtil.setValue(pool, "isWorking", false);
   mutableOne.updateData(data);
   FieldUtil.setValue(pool, "isWorking", true);
   mutableOne.updateData(makeAddress());
   mutableOne.updateData(data);
   assertEquals(2, readySet.size());
   // Check the backed queue
   LinkedBlockingQueue<RpcStub> readyQueue = FieldUtil.getValue(pool.poolHandler, "readyQueue");
   int delc = 0, addc = 0;
   for (RpcStub cli : readyQueue) {
     if (RpcUtil.isInUse(cli)) ++addc;
     else ++delc;
   }
   assertEquals(5, addc);
   assertEquals(5, delc);
 }
示例#11
0
 @Test
 public void testReallyBuildError() throws Exception {
   NodeInfo info = new NodeInfo();
   info.setProtocol("network/json");
   InetSocketAddress address = new InetSocketAddress("localhost", 8809);
   info.setAddress(address);
   info.setWeight(1);
   FieldUtil.setValue(pool, "weightShare", 0.6);
   pool.buildSuperClients(info);
   Set<RpcStub> clientSet = RpcStubPool.getPool().getClients(info.getAddress());
   assertEquals(0, clientSet.size());
 }
  @Test
  public void testOffer() throws Exception {
    RpcStub handler1 = makeHandler(2);
    RpcStub handler2 = makeHandler(0);

    MultiplexPoolHandler han = new MultiplexPoolHandler(Collections.singleton(handler1), 2, 2);
    han.offer(handler1);
    han.offer(handler2);
    LinkedBlockingQueue<RpcStub> readyQueue = FieldUtil.getValue(han, "readyQueue");
    assertEquals(2, readyQueue.size());
    assertEquals(handler1, readyQueue.take());
    assertEquals(handler1, readyQueue.take());
  }