Package net.rubyeye.xmemcached.command

Examples of net.rubyeye.xmemcached.command.Command


    command.encode();
    checkByteBufferEquals(command, "cas test 0 0 2 999 noreply\r\n10\r\n");
  }

  public void testSetEncode() {
    Command command = this.commandFactory.createSetCommand(key, key
        .getBytes(), exp, value, false, transcoder);
    assertNull(command.getIoBuffer());
    command.encode();
    checkByteBufferEquals(command, "set test 0 0 2\r\n10\r\n");
    command = this.commandFactory.createSetCommand(key, key.getBytes(),
        exp, value, true, transcoder);
    command.encode();
    checkByteBufferEquals(command, "set test 0 0 2 noreply\r\n10\r\n");
  }
View Full Code Here


    command.encode();
    checkByteBufferEquals(command, "set test 0 0 2 noreply\r\n10\r\n");
  }

  public void testAddEncode() {
    Command command = this.commandFactory.createAddCommand(key, key
        .getBytes(), exp, value, false, transcoder);
    assertNull(command.getIoBuffer());
    command.encode();
    checkByteBufferEquals(command, "add test 0 0 2\r\n10\r\n");

    command = this.commandFactory.createAddCommand(key, key.getBytes(),
        exp, value, true, transcoder);
    assertNull(command.getIoBuffer());
    command.encode();
    checkByteBufferEquals(command, "add test 0 0 2 noreply\r\n10\r\n");
  }
View Full Code Here

    command.encode();
    checkByteBufferEquals(command, "add test 0 0 2 noreply\r\n10\r\n");
  }

  public void testReplaceEncode() {
    Command command = this.commandFactory.createReplaceCommand(key, key
        .getBytes(), exp, value, false, transcoder);
    assertNull(command.getIoBuffer());
    command.encode();
    checkByteBufferEquals(command, "replace test 0 0 2\r\n10\r\n");

    command = this.commandFactory.createReplaceCommand(key, key.getBytes(),
        exp, value, true, transcoder);
    assertNull(command.getIoBuffer());
    command.encode();
    checkByteBufferEquals(command, "replace test 0 0 2 noreply\r\n10\r\n");
  }
View Full Code Here

    command.encode();
    checkByteBufferEquals(command, "replace test 0 0 2 noreply\r\n10\r\n");
  }

  public void testAppendEncode() {
    Command command = this.commandFactory.createAppendCommand(key, key
        .getBytes(), value, false, transcoder);
    assertNull(command.getIoBuffer());
    command.encode();
    checkByteBufferEquals(command, "append test 0 0 2\r\n10\r\n");

    command = this.commandFactory.createAppendCommand(key, key.getBytes(),
        value, true, transcoder);
    assertNull(command.getIoBuffer());
    command.encode();
    checkByteBufferEquals(command, "append test 0 0 2 noreply\r\n10\r\n");
  }
View Full Code Here

      final AtomicBoolean done = new AtomicBoolean(false);
      byte[] response = saslClient.hasInitialResponse() ? saslClient
          .evaluateChallenge(EMPTY_BYTES) : EMPTY_BYTES;
      CountDownLatch latch = new CountDownLatch(1);
      Command command = this.commandFactory.createAuthStartCommand(
          saslClient.getMechanismName(), latch, response);
      if (!this.memcachedTCPSession.isClosed())
        this.memcachedTCPSession.write(command);
      else {
        log
            .error("Authentication fail,because the connection has been closed");
        throw new RuntimeException(
            "Authentication fai,connection has been close");
      }

      while (!done.get()) {
        try {
          latch.await();
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
          done.set(true);
        }
        ResponseStatus responseStatus = ((BaseBinaryCommand) command)
            .getResponseStatus();
        switch (responseStatus) {
        case NO_ERROR:
          done.set(true);
          log.info("Authentication to "
              + this.memcachedTCPSession.getRemoteSocketAddress()
              + " successfully");
          break;
        case AUTH_REQUIRED:
          log
              .error("Authentication failed to "
                  + this.memcachedTCPSession
                      .getRemoteSocketAddress());
          log.warn("Reopen connection to "
              + this.memcachedTCPSession.getRemoteSocketAddress()
              + ",beacause auth fail");
          this.memcachedTCPSession.setAuthFailed(true);

          // It it is not first time,try to sleep 1 second
          if (!this.authInfo.isFirstTime()) {
            Thread.sleep(1000);
          }
          this.memcachedTCPSession.close();
          done.set(true);
          break;
        case FUTHER_AUTH_REQUIRED:
          String result = (String) command.getResult();
          response = saslClient.evaluateChallenge(ByteUtils
              .getBytes(result));
          latch = new CountDownLatch(1);
          command = commandFactory.createAuthStepCommand(saslClient
              .getMechanismName(), latch, response);
View Full Code Here

    return SystemUtils.getRawAddress(this.getRemoteSocketAddress()) + ":"
        + this.getRemoteSocketAddress().getPort();
  }

  public void destroy() {
    Command command = this.currentCommand.get();
    if (command != null) {
      command.setException(new MemcachedException(
          "Session has been closed"));
      command.getLatch().countDown();
    }
    while ((command = this.commandAlreadySent.poll()) != null) {
      command.setException(new MemcachedException(
          "Session has been closed"));
      if (command.getLatch() != null) {
        command.getLatch().countDown();
      }
    }

  }
View Full Code Here

    return result;
  }

  @Override
  protected WriteMessage preprocessWriteMessage(WriteMessage writeMessage) {
    Command currentCommand = (Command) writeMessage;
    // Check if IoBuffer is null
    if (currentCommand.getIoBuffer() == null) {
      currentCommand.encode();
    }
    if (currentCommand.getStatus() == OperationStatus.SENDING) {
      /**
       * optimieze commands
       */
      currentCommand = this.optimiezer.optimize(currentCommand,
          this.writeQueue, this.commandAlreadySent,
          this.sendBufferSize);
    }
    currentCommand.setStatus(OperationStatus.WRITING);
    return currentCommand;
  }
View Full Code Here

import net.rubyeye.xmemcached.command.CommandType;
import net.rubyeye.xmemcached.transcoders.CachedData;

public class TextGetOneCommandUnitTest extends BaseTextCommandUnitTest {
  public void testGetOneEncode() {
    Command command = this.commandFactory.createGetCommand("test", "test"
        .getBytes(), CommandType.GET_ONE, null);
    assertNull(command.getIoBuffer());
    command.encode();
    checkByteBufferEquals(command, "get test\r\n");
  }
View Full Code Here

    command.encode();
    checkByteBufferEquals(command, "get test\r\n");
  }

  public void testGetsOneEncode() {
    Command command = this.commandFactory.createGetCommand("test", "test"
        .getBytes(), CommandType.GETS_ONE, null);
    assertNull(command.getIoBuffer());
    command.encode();
    checkByteBufferEquals(command, "gets test\r\n");
  }
View Full Code Here

    command.encode();
    checkByteBufferEquals(command, "gets test\r\n");
  }

  public void testGetOneDecode() {
    Command command = this.commandFactory.createGetCommand("test", "test"
        .getBytes(), CommandType.GET_ONE, null);
    checkDecodeNullAndNotLineByteBuffer(command);
    checkDecodeInvalidLine(command, "STORED\r\n");
    checkDecodeInvalidLine(command, "NOT_FOUND\r\n");
    checkDecodeInvalidLine(command, "NOT_STORED\r\n");
    checkDecodeInvalidLine(command, "DELETED\r\n");

    checkDecodeValidLine(command, "END\r\n");
    assertNull(command.getResult());
    assertEquals(0, command.getLatch().getCount());

    command = this.commandFactory.createGetCommand("test", "test"
        .getBytes(), CommandType.GET_ONE, null);
    assertFalse(command.decode(null, ByteBuffer
        .wrap("VALUE test 0 2\r\n10\r\n".getBytes())));
    assertNull(command.getResult());

    assertFalse(command.decode(null, ByteBuffer.wrap("VALUE test 0 4\r\n1"
        .getBytes())));
    assertFalse(command.decode(null, ByteBuffer.wrap("0".getBytes())));
    assertFalse(command.decode(null, ByteBuffer.wrap("0".getBytes())));
    assertFalse(command.decode(null, ByteBuffer.wrap("0".getBytes())));
    checkDecodeValidLine(command, "\r\nEND\r\n");

    assertEquals("1000", new String(((CachedData) command.getResult())
        .getData()));
  }
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.