Skip to content

Commit

Permalink
ISPN-774 - Nonexistent memcached command should result in ERROR
Browse files Browse the repository at this point in the history
Corrected handling of unknown command exception.
  • Loading branch information
galderz committed Nov 18, 2010
1 parent 4d5b7ef commit 8e1eb2f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class AbstractProtocolDecoder[K, V <: CacheValue] extends Decoder {

override def decode(ctx: ChannelHandlerContext, buffer: ChannelBuffer): AnyRef = {
val header = readHeader(buffer)
if (header == null) return null // Something went wrong reading the header, so get more bytes
if (header == null) return null // Something went wrong reading the header, so get more bytes
try {
val ret = header.op match {
case PutRequest | PutIfAbsentRequest | ReplaceRequest | ReplaceIfUnmodifiedRequest | RemoveRequest => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ class MemcachedDecoder(cache: Cache[String, MemcachedValue], scheduler: Schedule
override def createErrorResponse(t: Throwable): AnyRef = {
val sb = new StringBuilder
t match {
case u: UnknownOperationException => ERROR
case se: ServerException => {
val cause = se.getCause
cause match {
case u: UnknownOperationException => ERROR
case c: ClosedChannelException => null // no-op, only log
case _ => {
cause match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class MemcachedFunctionalTest extends MemcachedSingleNodeTest {
assertEquals(version, Version.version)
}

def testKeyLengthLimit(m: Method) {
def testKeyLengthLimit {
val keyUnderLimit = generateRandomString(249)
var f = client.set(keyUnderLimit, 0, "78")
assertTrue(f.get(timeout, TimeUnit.SECONDS).booleanValue)
Expand All @@ -349,27 +349,40 @@ class MemcachedFunctionalTest extends MemcachedSingleNodeTest {
assertClientError(resp)
}

def testInvalidCas(m: Method) {
var resp = send("cas bad blah 0 0 0\r\n\r\n", 1024)
def testInvalidCas {
var resp = send("cas bad blah 0 0 0\r\n\r\n")
assertClientError(resp)

resp = send("cas bad 0 blah 0 0\r\n\r\n", 1024)
resp = send("cas bad 0 blah 0 0\r\n\r\n")
assertClientError(resp)

resp = send("cas bad 0 0 blah 0\r\n\r\n", 1024)
resp = send("cas bad 0 0 blah 0\r\n\r\n")
assertClientError(resp)

resp = send("cas bad 0 0 0 blah\r\n\r\n", 1024)
resp = send("cas bad 0 0 0 blah\r\n\r\n")
assertClientError(resp)
}

def testInvalidCasValue(m: Method) {
val resp = send("cas foo 0 0 6 \r\nbarva2\r\n", 1024)
def testInvalidCasValue {
val resp = send("cas foo 0 0 6 \r\nbarva2\r\n")
assertClientError(resp)
}

def testUnknownCommand {
val resp = send("blah\r\n")
assertError(resp)
}

private def assertClientError(resp: String) {
assertTrue(resp.contains("CLIENT_ERROR"), "Instead response is: " + resp)
assertExpectedError(resp, "CLIENT_ERROR")
}

private def assertError(resp: String) {
assertExpectedError(resp, "ERROR")
}

private def assertExpectedError(resp: String, expectedError: String) {
assertTrue(resp.contains(expectedError), "Instead response is: " + resp)
}

private def addAndGet(m: Method) {
Expand All @@ -386,6 +399,8 @@ class MemcachedFunctionalTest extends MemcachedSingleNodeTest {
send(req, expectedLength)
}

private def send(req: String): String = send(req, 1024)

private def send(req: String, expectedLength: Int): String = {
val socket = new Socket(server.getHost, server.getPort)
try {
Expand Down

0 comments on commit 8e1eb2f

Please sign in to comment.