Package net.rubyeye.xmemcached.command

Examples of net.rubyeye.xmemcached.command.Command


  }

  public void testMergeAllBuffer() {
    // merge 10 buffers
    this.optimiezer.setOptimizeMergeBuffer(true);
    Command optimiezeCommand = this.optimiezer.optimiezeMergeBuffer(
        this.currentCmd, this.writeQueue, this.executingCmds, 100);
    ByteBuffer mergeBuffer = optimiezeCommand.getIoBuffer().buf();
    assertNotSame(this.currentCmd, optimiezeCommand);
    assertTrue(mergeBuffer.remaining() < 100);
    assertEquals(0, this.writeQueue.size());
    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


        mergeBuffer.array())); // current command at last
  }

  public void testMergeBufferWithEmptyWriteQueue() {
    this.writeQueue.clear();
    Command optimiezeCommand = this.optimiezer.optimiezeMergeBuffer(
        this.currentCmd, this.writeQueue, this.executingCmds, 100);
    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("get 0\r\n", new String(mergeBuffer.array()));
View Full Code Here

  }

  public void testOptimieze() {
    this.optimiezer.setOptimizeMergeBuffer(true);
    for (int i = 0; i < 10; i++) {
      Command deleteCommand = this.commandFactory.createDeleteCommand(
          String.valueOf(i), String.valueOf(i).getBytes(), 0, false);
      deleteCommand.encode();
      this.writeQueue.add(deleteCommand);
      deleteCommand.setWriteFuture(new FutureImpl<Boolean>());
    }
    Command optimiezeCommand = this.optimiezer.optimize(this.currentCmd,
        this.writeQueue, this.executingCmds, 16 * 1024);
    ByteBuffer mergeBuffer = optimiezeCommand.getIoBuffer().buf();
    StringBuilder sb = new StringBuilder("get ");
    for (int i = 0; i < 10; i++) {
      if (i != 9) {
        sb.append(String.valueOf(i) + " ");
      } else {
View Full Code Here

  byte[] keyBytes = ByteUtils.getBytes(this.key);
  boolean noreply = false;

  public void testDeleteEncodeAndDecode() {

    Command command = this.commandFactory.createDeleteCommand(this.key,
        this.keyBytes, 0, this.noreply);
    command.encode();
    ByteBuffer encodeBuffer = command.getIoBuffer().buf();
    assertNotNull(encodeBuffer);
    assertEquals(29, encodeBuffer.capacity());

    byte opCode = encodeBuffer.get(1);
    assertEquals(OpCode.DELETE.fieldValue(), opCode);

    ByteBuffer buffer = constructResponse(OpCode.DELETE.fieldValue(),
        (short) 0, (byte) 0, (byte) 0, (short) 0, 0, 0, 1L, null, null,
        null);

    assertTrue(command.decode(null, buffer));
    assertTrue((Boolean) command.getResult());
    assertEquals(0, buffer.remaining());

    buffer = constructResponse(OpCode.DELETE.fieldValue(), (short) 0,
        (byte) 0, (byte) 0, (short) 0x0005, 0, 0, 1L, null, null, null);
    command = this.commandFactory.createDeleteCommand(this.key, this.keyBytes, 0,
        this.noreply);
    assertTrue(command.decode(null, buffer));
    assertFalse((Boolean) command.getResult());
    assertEquals(0, buffer.remaining());
  }
View Full Code Here

  public void testCreateDeleteCommand() {
    String key = "test";
    byte[] keyBytes = ByteUtils.getBytes(key);
    int time = 10;
    Command deleteCmd = this.commandFactory.createDeleteCommand("test",
        keyBytes, time,false);
    deleteCmd.encode();
    assertEquals(CommandType.DELETE, deleteCmd.getCommandType());
    String commandStr = new String(deleteCmd.getIoBuffer().buf()
        .array());

    String expectedStr = "delete test 10\r\n";

    assertEquals(expectedStr, commandStr);
View Full Code Here

    assertEquals(expectedStr, commandStr);
  }

  public void testCreateVersionCommand() {
    Command versionCmd = this.commandFactory.createVersionCommand(new CountDownLatch(1),null);
    versionCmd.encode();
    String commandStr = new String(versionCmd.getIoBuffer().buf()
        .array());
    assertEquals("version\r\n", commandStr);
    assertEquals(CommandType.VERSION, versionCmd.getCommandType());
  }
View Full Code Here

    String key = "test";
    String value = "test";
    byte[] keyBytes = ByteUtils.getBytes(key);
    int exp = 0;
    Transcoder transcoder = new StringTranscoder();
    Command storeCmd = this.commandFactory.createSetCommand(key, keyBytes, exp, value,false, transcoder);
    storeCmd.encode();
    assertFalse(storeCmd.isNoreply());
    assertEquals(CommandType.SET, storeCmd.getCommandType());
    String commandStr = new String(storeCmd.getIoBuffer().buf()
        .array());

    String expectedStr = "set test " + StringTranscoder.STRING_FLAG
        + " 0 4\r\ntest\r\n";
    assertEquals(expectedStr, commandStr);
View Full Code Here

  }

  public void testCreateGetCommand() {
    String key = "test";
    byte[] keyBytes = ByteUtils.getBytes(key);
    Command getCmd = this.commandFactory.createGetCommand(key, keyBytes,
        CommandType.GET_ONE, null);
    getCmd.encode();
    assertEquals(CommandType.GET_ONE, getCmd.getCommandType());
    String commandStr = new String(getCmd.getIoBuffer().buf()
        .array());

    String expectedStr = "get test\r\n";
    assertEquals(expectedStr, commandStr);
  }
View Full Code Here

  public void testCreateIncrDecrCommand() {
    String key = "test";
    byte[] keyBytes = ByteUtils.getBytes(key);
    int num = 10;
    Command inCr = this.commandFactory.createIncrDecrCommand(key, keyBytes,
        num, 0,0, CommandType.INCR, false);
    inCr.encode();
    assertEquals(CommandType.INCR, inCr.getCommandType());
    String commandStr = new String(inCr.getIoBuffer().buf()
        .array());

    String expectedStr = "incr test 10\r\n";
    assertEquals(expectedStr, commandStr);
View Full Code Here

    keys.add("a");
    keys.add("b");
    keys.add("c");
    keys.add("a");

    Command cmd = this.commandFactory.createGetMultiCommand(keys, null,
        CommandType.GET_MANY, null);
    cmd.encode();
    assertEquals(CommandType.GET_MANY, cmd.getCommandType());
    String commandStr = new String(cmd.getIoBuffer().buf()
        .array());

    String expectedStr = "get a b c a\r\n";
    assertEquals(expectedStr, commandStr);
  }
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.