Package net.rubyeye.xmemcached.command

Examples of net.rubyeye.xmemcached.command.Command


    }

    public void finish() {
      // prev command is the last command,last command must be getk,ensure
      // getq commands send response back
      Command lastGetKCommand = new BinaryGetCommand(
          prevCommand.getKey(), prevCommand.getKeyBytes(),
          CommandType.GET_ONE, new CountDownLatch(1), OpCode.GET_KEY,
          false);
      lastGetKCommand.encode();
      bufferList.add(lastGetKCommand.getIoBuffer());
      totalBytes += lastGetKCommand.getIoBuffer().remaining();
    }
View Full Code Here


    this.handler = new MemcachedHandler(this.memcachedClient);
  }

  @Test
  public void testOnMessageSent_TextCommand() {
    Command cmd = new TextVersionCommand(new CountDownLatch(1),
        new InetSocketAddress(8080));
    this.session.addCommand(cmd);
    EasyMock.expectLastCall();
    this.mocksControl.replay();
    this.handler.onMessageSent(this.session, cmd);
View Full Code Here

    this.mocksControl.verify();
  }

  @Test
  public void testOnMessageSent_TextCommand_NoReply() {
    Command cmd = new TextStoreCommand(null, null, null, null, 1, 1, null,
        true, null);
    EasyMock.expect(this.memcachedClient.getProtocol()).andReturn(
        Protocol.Text);
    this.mocksControl.replay();
    this.handler.onMessageSent(this.session, cmd);
View Full Code Here

    this.mocksControl.verify();
  }

  @Test
  public void testOnMessageSent_BinaryCommand() {
    Command cmd = new BinaryVersionCommand(null, null);
    this.session.addCommand(cmd);
    EasyMock.expectLastCall();
    this.mocksControl.replay();
    this.handler.onMessageSent(this.session, cmd);
    this.mocksControl.verify();
View Full Code Here

    this.mocksControl.verify();
  }

  @Test
  public void testOnMessageSent_BinaryCommand_NoReply() {
    Command cmd = new BinaryStoreCommand(null, null, CommandType.ADD, null,
        1, 1, null, true, null);
    EasyMock.expect(this.memcachedClient.getProtocol()).andReturn(
        Protocol.Binary);
    this.session.addCommand(cmd);
    EasyMock.expectLastCall();
View Full Code Here

    this.commandFactory = new TextCommandFactory();
    this.optimiezer.setBufferAllocator(new SimpleBufferAllocator());
    this.writeQueue = new LinkedTransferQueue<Command>();
    this.executingCmds = new LinkedTransferQueue<Command>();
    for (int i = 0; i < 10; i++) {
      Command cmd = this.commandFactory.createGetCommand(String
          .valueOf(i), String.valueOf(i).getBytes(),
          CommandType.GET_ONE, null);
      cmd.encode();
      this.writeQueue.add(cmd);
      cmd.setWriteFuture(new FutureImpl<Boolean>());
    }
    this.currentCmd = (Command) this.writeQueue.poll();
    this.currentCmd.encode();
  }
View Full Code Here

  public void testOptimiezeGetWithSameKey() {
    this.writeQueue.clear();
    Queue<Command> localQueue = new SimpleQueue<Command>();
    for (int i = 0; i < 10; i++) {
      Command cmd = this.commandFactory.createGetCommand(String
          .valueOf(0), String.valueOf(0).getBytes(),
          CommandType.GET_ONE, null);
      cmd.encode();
      this.writeQueue.add(cmd);
      cmd.setWriteFuture(new FutureImpl<Boolean>());
      localQueue.add(cmd);
    }
    TextGetOneCommand optimiezeCommand = (TextGetOneCommand) this.optimiezer
        .optimiezeGet(this.writeQueue, this.executingCmds,
            this.currentCmd);

    assertEquals(1, optimiezeCommand.getMergeCommands().size());
    assertEquals(11, optimiezeCommand.getMergeCount());
    assertEquals(0, this.writeQueue.size());
    assertNull(this.writeQueue.peek());
    assertSame(CommandType.GET_ONE, optimiezeCommand.getCommandType());
    assertEquals(11, optimiezeCommand.getMergeCount());
    assertEquals("get 0\r\n", new String(optimiezeCommand.getIoBuffer()
        .buf().array()));
    optimiezeCommand.decode(null, ByteBuffer.wrap("VALUE 0 0 2\r\n10\r\n"
        .getBytes()));

    assertEquals(0, this.currentCmd.getLatch().getCount());
    Transcoder transcoder = new SerializingTranscoder();
    assertEquals("10", transcoder.decode((CachedData) this.currentCmd
        .getResult()));
    for (Command cmd : localQueue) {
      assertEquals(0, cmd.getLatch().getCount());
      assertEquals("10", transcoder.decode((CachedData) this.currentCmd
          .getResult()));
    }
    assertEquals(0, optimiezeCommand.getMergeCount());
  }
View Full Code Here

  public void testMergeDifferenceCommands() {
    this.writeQueue.clear();
    // send five get operation,include current command
    for (int i = 0; i < 5; i++) {
      Command cmd = this.commandFactory.createGetCommand(String
          .valueOf(i), String.valueOf(i).getBytes(),
          CommandType.GET_ONE, null);
      this.writeQueue.add(cmd);
      cmd.setWriteFuture(new FutureImpl<Boolean>());
    }
    // send five delete operation
    for (int i = 5; i < 10; i++) {
      Command cmd = this.commandFactory.createDeleteCommand(String
          .valueOf(i), String.valueOf(i).getBytes(), 0, false);
      this.writeQueue.add(cmd);
      cmd.setWriteFuture(new FutureImpl<Boolean>());
    }
    // merge five get commands at most
    TextGetOneCommand optimiezeCommand = (TextGetOneCommand) this.optimiezer
        .optimiezeGet(this.writeQueue, this.executingCmds,
            this.currentCmd);
View Full Code Here

  }

  public void testMergeGetCommandsWithEmptyWriteQueue() {
    this.writeQueue.clear();
    Command optimiezeCommand = this.optimiezer.optimiezeGet(
        this.writeQueue, this.executingCmds, this.currentCmd);
    optimiezeCommand.encode();
    ByteBuffer mergeBuffer = optimiezeCommand.getIoBuffer().buf();
    assertSame(this.currentCmd, optimiezeCommand);
    assertTrue(mergeBuffer.remaining() < 100);
    assertSame(mergeBuffer, this.currentCmd.getIoBuffer().buf());
    assertEquals(0, this.writeQueue.size());
    assertEquals(-1, optimiezeCommand.getMergeCount());
    assertEquals("get 0\r\n", new String(mergeBuffer.array()));
  }
View Full Code Here

  }

  public void testMergeLimitBuffer() {
    // set send buffer size to 30,merge four commands at most
    this.optimiezer.setOptimizeMergeBuffer(true);
    Command optimiezeCommand = this.optimiezer.optimiezeMergeBuffer(
        this.currentCmd, this.writeQueue, this.executingCmds, 30);
    assertNotSame(this.currentCmd, optimiezeCommand);
    ByteBuffer mergeBuffer = optimiezeCommand.getIoBuffer().buf();
    assertEquals(0, this.writeQueue.size());
    assertSame(CommandType.GET_ONE, optimiezeCommand.getCommandType());
    assertEquals("get 0\r\nget 1 2 3 4 5 6 7 8 9\r\n", new String(
        mergeBuffer.array())); // current command at last
  }
View Full Code Here

TOP

Related Classes of net.rubyeye.xmemcached.command.Command

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.