Package net.rubyeye.xmemcached

Examples of net.rubyeye.xmemcached.MemcachedClient


    Assert.assertEquals("hello world", this.memcachedClient
        .get("queue1/open"));
    // close connection
    this.memcachedClient.shutdown();
    // still can fetch it
    MemcachedClient newClient = newBuilder().build();
    newClient.setOptimizeGet(false);
    // begin transaction
    Assert.assertEquals("hello world", newClient.get("queue1/open"));
    // confirm
    Assert.assertNull(newClient.get("queue1/close"));
    Assert.assertNull(newClient.get("queue1"));

    // test abort,for kestrel 1.2
    Assert.assertTrue(newClient.set("queue1", 0, "hello world"));
    Assert.assertEquals("hello world", newClient.get("queue1/open"));
    // abort
    Assert.assertNull(newClient.get("queue1/abort"));
    // still alive
    Assert.assertEquals("hello world", newClient.get("queue1/open"));
    // confirm
    Assert.assertNull(newClient.get("queue1/close"));
    // null
    Assert.assertNull(newClient.get("queue1"));

    newClient.shutdown();
  }
View Full Code Here


    MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil
        .getAddressMap("localhost:4799,localhost:4798"));
    // It must be in failure mode
    builder.setFailureMode(true);
    MemcachedClient client = builder.build();

    client.setEnableHeartBeat(false);

    try {

      assertEquals("response from server1", client.get("a"));
      assertEquals("response from server1", client.get("a"));
      memServer1.stop();
      Thread.sleep(1000);
      assertEquals("response from server2", client.get("a"));
      // restart server1
      memServer1 = new TCPController();
      memServer1.setHandler(new MockHandler("response from server1"));
      memServer1.setCodecFactory(new TextLineCodecFactory());
      memServer1.bind(new InetSocketAddress(4799));
      Thread.sleep(5000);
      assertEquals("response from server1", client.get("a"));
    } finally {
      memServer1.stop();
      memServer2.stop();
      client.shutdown();
    }

  }
View Full Code Here

    MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil
        .getAddressMap("localhost:4799 localhost:4798"));
    // It must be in failure mode
    builder.setFailureMode(true);
    MemcachedClient client = builder.build();

    client.setEnableHeartBeat(false);
    TCPController memServer1 = null;
    try {

      assertEquals("response from server2", client.get("a"));
      try {
        assertEquals("response from server1", client.get("b"));
        fail();
      } catch (MemcachedException e) {
        assertEquals("Session(127.0.0.1:4799) has been closed", e
            .getMessage());
      }
      assertEquals(1, client.getConnector().getSessionByAddress(
          AddrUtil.getOneAddress("localhost:4799")).size());
      memServer1 = new TCPController();
      memServer1.setHandler(new MockHandler("response from server1"));
      memServer1.setCodecFactory(new TextLineCodecFactory());
      memServer1.bind(new InetSocketAddress(4799));
      Thread.sleep(5000);
      assertEquals(1, client.getConnector().getSessionByAddress(
          AddrUtil.getOneAddress("localhost:4799")).size());
      assertEquals("response from server2", client.get("a"));
      assertEquals("response from server1", client.get("b"));
    } finally {
      if (memServer1 != null)
        memServer1.stop();
      memServer2.stop();
      client.shutdown();
    }

  }
View Full Code Here

    MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil
        .getAddressMap("localhost:4799,localhost:4798"));
    // It must be in failure mode
    builder.setFailureMode(true);
    MemcachedClient client = builder.build();

    client.setEnableHeartBeat(false);

    try {
      assertEquals("response from server1", client.get("a"));
      assertEquals("response from server1", client.get("a"));
      memServer1.stop();
      Thread.sleep(1000);
      assertEquals("response from server2", client.get("a"));
      memServer2.stop();
      Thread.sleep(1000);
      try {
        client.get("a");
        fail();
      } catch (MemcachedException e) {
        assertEquals("Session(127.0.0.1:4799) has been closed", e
            .getMessage());
        // e.printStackTrace();
      }
      // restart server2
      memServer2 = new TCPController();
      memServer2.setHandler(new MockHandler("response from server2"));
      memServer2.setCodecFactory(new TextLineCodecFactory());
      memServer2.bind(new InetSocketAddress(4798));
      Thread.sleep(5000);
      assertEquals("response from server2", client.get("a"));

      // restart server1
      memServer1 = new TCPController();
      memServer1.setHandler(new MockHandler("response from server1"));
      memServer1.setCodecFactory(new TextLineCodecFactory());
      memServer1.bind(new InetSocketAddress(4799));
      Thread.sleep(10000);
      assertEquals("response from server1", client.get("a"));

    } finally {
      memServer1.stop();
      memServer2.stop();
      client.shutdown();
    }

  }
View Full Code Here

    memServer1.bind(new InetSocketAddress(4799));

    MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil
        .getAddressMap("localhost:4799"));
    builder.setFailureMode(true);
    MemcachedClient client = builder.build();

    client.setEnableHeartBeat(false);

    try {

      assertEquals("response from server1", client.get("a"));
      assertEquals("response from server1", client.get("a"));
      memServer1.stop();
      Thread.sleep(1000);
      try {
        client.get("a");
        fail();
      } catch (MemcachedException e) {
        assertEquals("Session(127.0.0.1:4799) has been closed", e
            .getMessage());
        assertTrue(true);
      }
    } finally {
      memServer1.stop();
      client.shutdown();
    }

  }
View Full Code Here

    memServer2.setCodecFactory(new TextLineCodecFactory());
    memServer2.bind(new InetSocketAddress(4798));

    MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil
        .getAddressMap("localhost:4799,localhost:4798"));
    MemcachedClient client = builder.build();

    client.setEnableHeartBeat(false);
    try {

      assertEquals("response from server1", client.get("a"));
      assertEquals("response from server1", client.get("a"));
      memServer1.stop();
      Thread.sleep(1000);
      try {
        client.get("a");
        fail();
      } catch (MemcachedException e) {
        assertEquals("There is no available connection at this moment",
            e.getMessage());
        assertTrue(true);
      }
    } finally {
      memServer1.stop();
      memServer2.stop();
      client.shutdown();
    }

  }
View Full Code Here

    memServer1.setCodecFactory(new TextLineCodecFactory());
    memServer1.bind(new InetSocketAddress(4799));

    MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil
        .getAddressMap("localhost:4799"));
    MemcachedClient client = builder.build();

    client.setEnableHeartBeat(false);
    try {

      assertEquals("response from server1", client.get("a"));
      assertEquals("response from server1", client.get("a"));
      memServer1.stop();
      Thread.sleep(1000);
      try {
        client.get("a");
        fail();
      } catch (MemcachedException e) {
        assertEquals("There is no available connection at this moment",
            e.getMessage());
        assertTrue(true);
      }
    } finally {
      memServer1.stop();
      client.shutdown();
    }

  }
View Full Code Here

    memServer2.setCodecFactory(new TextLineCodecFactory());
    memServer2.bind(new InetSocketAddress(4798));

    MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil
        .getAddressMap("localhost:4799 localhost:4798"));
    MemcachedClient client = builder.build();

    client.setEnableHeartBeat(false);

    try {

      assertEquals("response from server2", client.get("a"));
      assertEquals("response from server2", client.get("a"));
      memServer2.stop();
      Thread.sleep(1000);
      assertEquals("response from server1", client.get("a"));
    } finally {
      memServer1.stop();
      memServer2.stop();
      client.shutdown();
    }

  }
View Full Code Here

    createClients();
    mockTranscoder = new MockTranscoder();
  }

  public void testCreateClientWithEmptyServers() throws Exception {
    MemcachedClient client = new XMemcachedClient();
    assertFalse(client.isShutdown());
    client.shutdown();
    assertTrue(client.isShutdown());

    MemcachedClientBuilder builder = new XMemcachedClientBuilder();
    client = builder.build();
    assertFalse(client.isShutdown());
    client.shutdown();
    assertTrue(client.isShutdown());
  }
View Full Code Here

    createClients();
    mockTranscoder = new MockTranscoder();
  }

  public void testCreateClientWithEmptyServers() throws Exception {
    MemcachedClient client = new XMemcachedClient();
    assertFalse(client.isShutdown());
    client.shutdown();
    assertTrue(client.isShutdown());

    MemcachedClientBuilder builder = new XMemcachedClientBuilder();
    client = builder.build();
    assertFalse(client.isShutdown());
    client.shutdown();
    assertTrue(client.isShutdown());
  }
View Full Code Here

TOP

Related Classes of net.rubyeye.xmemcached.MemcachedClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.