ó
[³XMc           @   sç   d  Z  d d l m Z d d l m Z m Z d d l m Z m Z d d l m	 Z	 d d l
 m Z d d l m Z d d l m Z m Z m Z d d	 l m Z d
 f  d „  ƒ  YZ d e e	 f d „  ƒ  YZ d e e	 f d „  ƒ  YZ d S(   s$   
Test the memcache client protocol.
iÿÿÿÿ(   t   ConnectionDone(   t   MemCacheProtocolt   NoSuchCommand(   t   ClientErrort   ServerError(   t   TestCase(   t    StringTransportWithDisconnection(   t   Clock(   t   Deferredt   gatherResultst   TimeoutError(   t   DeferredListt   CommandMixinc           B   sÂ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sO   
    Setup and tests for basic invocation of L{MemCacheProtocol} commands.
    c         C   s   t  ƒ  ‚ d S(   sp   
        Helper test method to test the resulting C{Deferred} of a
        L{MemCacheProtocol} command.
        N(   t   NotImplementedError(   t   selft   dt   sendt   recvt   result(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   _test   s    c         C   s"   |  j  |  j j d ƒ d d d ƒ S(   sÉ   
        L{MemCacheProtocol.get} returns a L{Deferred} which is called back with
        the value and the flag associated with the given key if the server
        returns a successful result.
        t   foos	   get foo
s   VALUE foo 0 3
bar
END
i    t   bar(   i    R   (   R   t   protot   get(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_get"   s    c         C   s"   |  j  |  j j d ƒ d d d ƒ S(   su   
        Test getting a non-available key: it succeeds but return C{None} as
        value and C{0} as flag.
        R   s	   get foo
s   END
i    N(   i    N(   R   R   R   t   None(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_emptyGet,   s    c         C   s6   |  j  |  j j d d g ƒ d d i d d 6d	 d 6ƒ S(
   s™   
        L{MemCacheProtocol.getMultiple} returns a L{Deferred} which is called
        back with a dictionary of flag, value for each given key.
        R   t   cows   get foo cow
s1   VALUE foo 0 3
bar
VALUE cow 0 7
chicken
END
i    t   chickenR   (   i    R   (   i    s   bar(   R   R   t   getMultiple(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_getMultiple5   s    c         C   s6   |  j  |  j j d d g ƒ d d i d d 6d
 d 6ƒ S(   s‰   
        When L{MemCacheProtocol.getMultiple} is called with non-available keys,
        the corresponding tuples are (0, None).
        R   R   s   get foo cow
s   VALUE cow 1 3
bar
END
i   R   i    (   i   s   barN(   i    N(   R   R   R   R   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_getMultipleWithEmpty@   s    c         C   s%   |  j  |  j j d d ƒ d d t ƒ S(   s†   
        L{MemCacheProtocol.set} returns a L{Deferred} which is called back with
        C{True} when the operation succeeds.
        R   R   s   set foo 0 0 3
bar
s   STORED
(   R   R   t   sett   True(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_setK   s    c         C   s%   |  j  |  j j d d ƒ d d t ƒ S(   s†   
        L{MemCacheProtocol.add} returns a L{Deferred} which is called back with
        C{True} when the operation succeeds.
        R   R   s   add foo 0 0 3
bar
s   STORED
(   R   R   t   addR!   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_addT   s    c         C   s%   |  j  |  j j d d ƒ d d t ƒ S(   sŠ   
        L{MemCacheProtocol.replace} returns a L{Deferred} which is called back
        with C{True} when the operation succeeds.
        R   R   s   replace foo 0 0 3
bar
s   STORED
(   R   R   t   replaceR!   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_replace]   s    c         C   s%   |  j  |  j j d d ƒ d d t ƒ S(   sæ   
        Test an erroneous add: if a L{MemCacheProtocol.add} is called but the
        key already exists on the server, it returns a B{NOT STORED} answer,
        which calls back the resulting L{Deferred} with C{False}.
        R   R   s   add foo 0 0 3
bar
s   NOT STORED
(   R   R   R#   t   False(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_errorAddf   s    c         C   s%   |  j  |  j j d d ƒ d d t ƒ S(   sí   
        Test an erroneous replace: if a L{MemCacheProtocol.replace} is called
        but the key doesn't exist on the server, it returns a B{NOT STORED}
        answer, which calls back the resulting L{Deferred} with C{False}.
        R   R   s   replace foo 0 0 3
bar
s   NOT STORED
(   R   R   R%   R'   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_errorReplacep   s    c         C   s"   |  j  |  j j d ƒ d d t ƒ S(   s   
        L{MemCacheProtocol.delete} returns a L{Deferred} which is called back
        with C{True} when the server notifies a success.
        R   s   delete bar
s	   DELETED
(   R   R   t   deleteR!   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_deletez   s    c         C   s"   |  j  |  j j d ƒ d d t ƒ S(   s¾   
        Test a error during a delete: if key doesn't exist on the server, it
        returns a B{NOT FOUND} answer which calls back the resulting L{Deferred}
        with C{False}.
        R   s   delete bar
s   NOT FOUND
(   R   R   R*   R'   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_errorDeleteƒ   s    c         C   s"   |  j  |  j j d ƒ d d d ƒ S(   sµ   
        Test incrementing a variable: L{MemCacheProtocol.increment} returns a
        L{Deferred} which is called back with the incremented value of the
        given key.
        R   s   incr foo 1
s   4
i   (   R   R   t	   increment(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_increment   s    c         C   s"   |  j  |  j j d ƒ d d d ƒ S(   sµ   
        Test decrementing a variable: L{MemCacheProtocol.decrement} returns a
        L{Deferred} which is called back with the decremented value of the
        given key.
        R   s   decr foo 1
s   5
i   (   R   R   t	   decrement(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_decrement—   s    c         C   s%   |  j  |  j j d d ƒ d d d ƒ S(   s‘   
        L{MemCacheProtocol.increment} takes an optional argument C{value} which
        replaces the default value of 1 when specified.
        R   i   s   incr foo 8
s   4
i   (   R   R   R-   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_incrementVal¡   s    c         C   s%   |  j  |  j j d d ƒ d d d ƒ S(   s‘   
        L{MemCacheProtocol.decrement} takes an optional argument C{value} which
        replaces the default value of 1 when specified.
        R   i   s   decr foo 3
s   5
i   (   R   R   R/   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_decrementValª   s    c         C   s-   |  j  |  j j ƒ  d d i d d 6d d 6ƒ S(   së   
        Test retrieving server statistics via the L{MemCacheProtocol.stats}
        command: it parses the data sent by the server and calls back the
        resulting L{Deferred} with a dictionary of the received statistics.
        s   stats
s"   STAT foo bar
STAT egg spam
END
R   R   t   spamt   egg(   R   R   t   stats(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt
   test_stats³   s    c         C   s0   |  j  |  j j d ƒ d d i d d 6d d 6ƒ S(   s7  
        L{MemCacheProtocol.stats} takes an optional C{str} argument which,
        if specified, is sent along with the I{STAT} command.  The I{STAT}
        responses from the server are parsed as key/value pairs and returned
        as a C{dict} (as in the case where the argument is not specified).
        t   blahs   stats blah
s"   STAT foo bar
STAT egg spam
END
R   R   R3   R4   (   R   R   R5   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_statsWithArgument¾   s    c         C   s   |  j  |  j j ƒ  d d d ƒ S(   s¸   
        Test version retrieval via the L{MemCacheProtocol.version} command: it
        returns a L{Deferred} which is called back with the version sent by the
        server.
        s	   version
s   VERSION 1.1
s   1.1(   R   R   t   version(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_versionÊ   s    c         C   s   |  j  |  j j ƒ  d d t ƒ S(   s’   
        L{MemCacheProtocol.flushAll} returns a L{Deferred} which is called back
        with C{True} if the server acknowledges success.
        s   flush_all
s   OK
(   R   R   t   flushAllR!   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_flushAllÔ   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R"   R$   R&   R(   R)   R+   R,   R.   R0   R1   R2   R6   R8   R:   R<   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyR      s*   		
											
	
			
	
	
							
t   MemCacheTestCasec           B   s
  e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s9   
    Test client protocol class L{MemCacheProtocol}.
    c         C   s\   t  ƒ  |  _ t ƒ  |  _ |  j j |  j _ t ƒ  |  _ |  j |  j _ |  j j |  j ƒ d S(   s{   
        Create a memcache client, connect it to a string protocol, and make it
        use a deterministic clock.
        N(	   R   R   R   t   clockt	   callLaterR   t	   transportt   protocolt   makeConnection(   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   setUpã   s    c            sL   ‡  ‡ f d †  } ˆ  j  ˆ  j j ƒ  | ƒ | j | ƒ ˆ  j j | ƒ | S(   sñ  
        Implementation of C{_test} which checks that the command sends C{send}
        data, and that upon reception of C{recv} the result is C{result}.

        @param d: the resulting deferred from the memcache command.
        @type d: C{Deferred}

        @param send: the expected data to be sent.
        @type send: C{str}

        @param recv: the data to simulate as reception.
        @type recv: C{str}

        @param result: the expected result.
        @type result: C{any}
        c            s   ˆ  j  |  ˆ ƒ d  S(   N(   t   assertEquals(   t   res(   R   R   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   cb  s    (   RG   RC   t   valuet   addCallbackR   t   dataReceived(   R   R   R   R   R   RI   (    (   R   R   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyR   ð   s
    c         C   sC   |  j  j d ƒ d } |  j t |  j  j d t | ƒ | f ƒ d S(   s¥   
        If the value returned doesn't match the expected key of the current
        C{get} command, an error is raised in L{MemCacheProtocol.dataReceived}.
        R   t   spameggs   VALUE bar 0 %s
%s
END
N(   R   R   t   assertRaisest   RuntimeErrorRL   t   len(   R   t   s(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_invalidGetResponse	  s
    		c         C   sI   |  j  j d d g ƒ d } |  j t |  j  j d t | ƒ | f ƒ d S(   sÁ   
        If the value returned doesn't match one the expected keys of the
        current multiple C{get} command, an error is raised error in
        L{MemCacheProtocol.dataReceived}.
        R   R   RM   s   VALUE egg 0 %s
%s
END
N(   R   R   RN   RO   RL   RP   (   R   RQ   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_invalidMultipleGetResponse  s
    		c            s¡   ˆ  j  j d ƒ } ˆ  j  j d ƒ } t ƒ  } | j ˆ  j  _ ˆ  j j ˆ  j  j ƒ ˆ  j | t	 ƒ ˆ  j | t	 ƒ ‡  f d †  } | j
 | ƒ t | | | g ƒ S(   s²   
        Test the timeout on outgoing requests: when timeout is detected, all
        current commands fail with a L{TimeoutError}, and the connection is
        closed.
        R   R   c            s   ˆ  j  t |  ƒ d ƒ d  S(   Ns   Connection timeout(   RG   t   str(   t   error(   R   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   checkMessage0  s    (   R   R   R   t   callbackt   connectionLostRA   t   advancet   persistentTimeOutt   assertFailureR
   RK   R	   (   R   t   d1t   d2t   d3RV   (    (   R   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_timeOut"  s    	c            s\   ˆ  j  j d ƒ } ˆ  j j ˆ  j  j d ƒ ˆ  j  j d ƒ ‡  f d †  } | j | ƒ | S(   sY   
        When a request gets a response, no pending timeout call remains around.
        R   i   s   VALUE foo 0 3
bar
END
c            s0   ˆ  j  |  d ƒ ˆ  j  t ˆ  j j ƒ d ƒ d  S(   Ni    R   (   i    s   bar(   RG   RP   RA   t   calls(   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   check?  s    (   R   R   RA   RY   RZ   RL   RK   (   R   R   Ra   (    (   R   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_timeoutRemoved6  s    c         C   sp   |  j  j d ƒ } t ƒ  } | j |  j  _ |  j  j d ƒ |  j j |  j  j ƒ |  j	 | t
 ƒ t | | g ƒ S(   sÈ   
        Test the timeout when raw mode was started: the timeout is not reset
        until all the data has been received, so we can have a L{TimeoutError}
        when waiting for raw data.
        R   s   VALUE foo 0 10
12345(   R   R   R   RW   RX   RL   RA   RY   RZ   R[   R
   R	   (   R   R\   R]   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_timeOutRawF  s    	c         C   sm   |  j  j ƒ  } t ƒ  } | j |  j  _ |  j  j d ƒ |  j j |  j  j ƒ |  j	 | t
 ƒ t | | g ƒ S(   s†   
        Test the timeout when stat command has started: the timeout is not
        reset until the final B{END} is received.
        s   STAT foo bar
(   R   R5   R   RW   RX   RL   RA   RY   RZ   R[   R
   R	   (   R   R\   R]   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_timeOutStatV  s    	c            s›   ˆ j  j d ƒ } ˆ j  j d ƒ ‰ t ƒ  } | j ˆ j  _ ˆ j j ˆ j  j d ƒ ˆ j  j d ƒ ‡  ‡ ‡ f d †  } ‡ f d †  ‰  | j	 | ƒ | S(   sŒ   
        When two requests are sent, a timeout call remains around for the
        second request, and its timeout time is correct.
        R   R   i   s   VALUE foo 0 3
bar
END
c            sr   ˆ j  |  d ƒ ˆ j  t ˆ j j ƒ d ƒ x* t ˆ j j ƒ D] } ˆ j j d ƒ q? Wˆ j ˆ t	 ƒ j
 ˆ  ƒ S(   Ni    R   i   (   i    s   bar(   RG   RP   RA   R`   t   rangeR   RZ   RY   R[   R
   RK   (   R   t   i(   t	   checkTimeR   R]   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyRa   r  s
    c            s+   ˆ  j  ˆ  j j ƒ  d ˆ  j j d ƒ d  S(   Ni   i   (   RG   RA   t   secondsR   RZ   (   t   ignored(   R   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyRg   x  s    (
   R   R   R   RW   RX   RA   RY   RZ   RL   RK   (   R   R\   R^   Ra   (    (   Rg   R   R]   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_timeoutPipelininge  s    	c         C   s™   |  j  j d ƒ } t ƒ  } | j |  j  _ |  j j |  j  j d ƒ |  j  j d ƒ } |  j j d ƒ |  j | t	 ƒ |  j | t	 ƒ t
 | | | g ƒ S(   s   
        Check that timeout is not resetted for every command, but keep the
        timeout from the first command without response.
        R   i   R   (   R   R   R   RW   RX   RA   RY   RZ   R[   R
   R	   (   R   R\   R^   R]   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_timeoutNotReset  s    	c         C   sj   |  j  j d ƒ } |  j j |  j  j ƒ |  j | t ƒ |  j  j d ƒ } |  j | t ƒ t | | g ƒ S(   s  
        C{timeoutConnection} cleans the list of commands that it fires with
        C{TimeoutError}: C{connectionLost} doesn't try to fire them again, but
        sets the disconnected state so that future commands fail with a
        C{RuntimeError}.
        R   R   (	   R   R   RA   RY   RZ   R[   R
   RO   R	   (   R   R\   R]   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_timeoutCleanDeferreds’  s    c            se   ˆ  j  j d ƒ } ˆ  j  j d ƒ } ˆ  j j ƒ  t | | g d t ƒ} ‡  f d †  } | j | ƒ S(   sl   
        When disconnection occurs while commands are still outstanding, the
        commands fail.
        R   R   t   consumeErrorsc            s5   x. |  D]& \ } } ˆ  j  | ƒ | j t ƒ q Wd  S(   N(   t   assertFalset   trapR    (   t   resultst   successR   (   R   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   checkFailuresª  s    (   R   R   RC   t   loseConnectionR   R!   RK   (   R   R\   R]   t   doneRr   (    (   R   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_connectionLost¡  s    c         C   s÷   |  j  |  j j d d d ƒ t ƒ } |  j  |  j j d d ƒ t ƒ } |  j  |  j j d d ƒ t ƒ } |  j  |  j j d d d ƒ t ƒ } |  j  |  j j d d d ƒ t ƒ } |  j  |  j j d d d g ƒ t ƒ } t	 | | | | | | g ƒ S(   s›   
        An error is raised when trying to use a too long key: the called
        command returns a L{Deferred} which fails with a L{ClientError}.
        t   aiô  R   R   (
   R[   R   R    R   R-   R   t   appendt   prependR   R	   (   R   R\   R]   R^   t   d4t   d5t   d6(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_tooLongKey±  s    %"""c         C   s^   |  j  j d d d d d d ƒ } |  j |  j j ƒ  d ƒ |  j | t ƒ |  j  j d ƒ | S(   s¼   
        When an unknown command is sent directly (not through public API), the
        server answers with an B{ERROR} token, and the command fails with
        L{NoSuchCommand}.
        R4   R   R   i    t    s   egg foo 0 0 3
bar
s   ERROR
(   R   t   _setRG   RC   RJ   R[   R   RL   (   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_invalidCommandÂ  s
    !c            st   d } ˆ  j  j d | ƒ } ˆ  j ˆ  j j ƒ  d ƒ ˆ  j | t ƒ ‡  f d †  } | j | ƒ ˆ  j  j d ƒ | S(   sÖ   
        Test the L{ClientError} error: when the server sends a B{CLIENT_ERROR}
        token, the originating command fails with L{ClientError}, and the error
        contains the text sent by the server.
        t   eggspammR   s   set foo 0 0 8
eggspamm
c            s   ˆ  j  t |  ƒ d ƒ d  S(   Ns   We don't like egg and spam(   RG   RT   (   t   err(   R   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyRa   Ú  s    s)   CLIENT_ERROR We don't like egg and spam
(	   R   R    RG   RC   RJ   R[   R   RK   RL   (   R   Rv   R   Ra   (    (   R   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_clientErrorÏ  s    c            st   d } ˆ  j  j d | ƒ } ˆ  j ˆ  j j ƒ  d ƒ ˆ  j | t ƒ ‡  f d †  } | j | ƒ ˆ  j  j d ƒ | S(   sÖ   
        Test the L{ServerError} error: when the server sends a B{SERVER_ERROR}
        token, the originating command fails with L{ServerError}, and the error
        contains the text sent by the server.
        R€   R   s   set foo 0 0 8
eggspamm
c            s   ˆ  j  t |  ƒ d ƒ d  S(   Nt   zomg(   RG   RT   (   R   (   R   (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyRa   ì  s    s   SERVER_ERROR zomg
(	   R   R    RG   RC   RJ   R[   R   RK   RL   (   R   Rv   R   Ra   (    (   R   s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_serverErrorá  s    c         C   s   |  j  |  j j d d ƒ t ƒ } |  j  |  j j d ƒ t ƒ } |  j  |  j j d ƒ t ƒ } |  j  |  j j d ƒ t ƒ } |  j  |  j j d d ƒ t ƒ } |  j  |  j j d d ƒ t ƒ } |  j  |  j j	 d d g ƒ t ƒ } t
 | | | | | | | g ƒ S(   sQ   
        Using a non-string key as argument to commands raises an error.
        u   fooR   u   eggi   u   barR4   (   R[   R   R    R   R-   R   R*   Rw   Rx   R   R	   (   R   R\   R]   R^   Ry   Rz   R{   t   d7(    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_unicodeKeyó  s    !!!c         C   s   |  j  |  j j d d ƒ t ƒ S(   s;   
        Using a non-string value raises an error.
        R   u   bar(   R[   R   R    R   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_unicodeValue  s    c         C   s®   |  j  j d ƒ } | j |  j d	 ƒ |  j  j d d ƒ } | j |  j t ƒ |  j  j d ƒ } | j |  j d
 ƒ |  j |  j j ƒ  d ƒ |  j  j d ƒ t	 | | | g ƒ S(   s½   
        Multiple requests can be sent subsequently to the server, and the
        protocol orders the responses correctly and dispatch to the
        corresponding client command.
        R   i    R   t   spamspamspamR4   R3   s0   get foo
set bar 0 0 12
spamspamspam
get egg
s;   VALUE foo 0 3
bar
END
STORED
VALUE egg 0 4
spam
END
(   i    s   bar(   i    s   spam(
   R   R   RK   RG   R    R!   RC   RJ   RL   R	   (   R   R\   R]   R^   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_pipelining	  s    c         C   s‚   |  j  j d ƒ } | j |  j d	 ƒ |  j |  j j ƒ  d ƒ |  j  j d ƒ |  j  j d ƒ |  j  j d ƒ |  j  j d ƒ | S(
   s”   
        If the value retrieved by a C{get} arrive in chunks, the protocol
        is able to reconstruct it and to produce the good value.
        R   i    t
   0123456789s	   get foo
s   VALUE foo 0 10
0123456t   789s   
ENDs   
(   i    RŠ   (   R   R   RK   RG   RC   RJ   RL   (   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_getInChunks  s    c         C   s%   |  j  |  j j d d ƒ d d t ƒ S(   sÃ   
        L{MemCacheProtocol.append} behaves like a L{MemCacheProtocol.set}
        method: it returns a L{Deferred} which is called back with C{True} when
        the operation succeeds.
        R   R   s   append foo 0 0 3
bar
s   STORED
(   R   R   Rw   R!   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_append,  s    c         C   s%   |  j  |  j j d d ƒ d d t ƒ S(   sÄ   
        L{MemCacheProtocol.prepend} behaves like a L{MemCacheProtocol.set}
        method: it returns a L{Deferred} which is called back with C{True} when
        the operation succeeds.
        R   R   s   prepend foo 0 0 3
bar
s   STORED
(   R   R   Rx   R!   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_prepend6  s    c         C   s%   |  j  |  j j d t ƒ d d d ƒ S(   s©   
        L{MemCacheProtocol.get} handles an additional cas result when
        C{withIdentifier} is C{True} and forward it in the resulting
        L{Deferred}.
        R   s
   gets foo
s   VALUE foo 0 3 1234
bar
END
i    t   1234R   (   i    R   s   bar(   R   R   R   R!   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt	   test_gets@  s    c         C   s%   |  j  |  j j d t ƒ d d d ƒ S(   s“   
        Test getting a non-available key with gets: it succeeds but return
        C{None} as value, C{0} as flag and an empty cas value.
        R   s
   gets foo
s   END
i    R}   N(   i    R}   N(   R   R   R   R!   R   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_emptyGetsJ  s    c         C   s9   |  j  |  j j d d g t ƒ d d i d
 d 6d d 6ƒ S(   s‘   
        L{MemCacheProtocol.getMultiple} handles an additional cas field in the
        returned tuples if C{withIdentifier} is C{True}.
        R   R   s   gets foo bar
s8   VALUE foo 0 3 1234
egg
VALUE bar 0 4 2345
spam
END
i    t   2345R3   R   R4   (   i    R’   s   spam(   i    s   1234s   egg(   R   R   R   R!   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_getsMultipleS  s    c         C   s9   |  j  |  j j d d g t ƒ d d i d
 d 6d d 6ƒ S(   s  
        When getting a non-available key with L{MemCacheProtocol.getMultiple}
        when C{withIdentifier} is C{True}, the other keys are retrieved
        correctly, and the non-available key gets a tuple of C{0} as flag,
        C{None} as value, and an empty cas value.
        R   R   s   gets foo bar
s   VALUE foo 0 3 1234
egg
END
i    R}   R   R4   N(   i    R}   N(   i    s   1234s   egg(   R   R   R   R!   R   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_getsMultipleWithEmpty^  s    c         C   s+   |  j  |  j j d d d d ƒd d t ƒ S(   s   
        L{MemCacheProtocol.checkAndSet} passes an additional cas identifier
        that the server handles to check if the data has to be updated.
        R   R   t   casR   s   cas foo 0 0 3 1234
bar
s   STORED
(   R   R   t   checkAndSetR!   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_checkAndSetk  s    c         C   s+   |  j  |  j j d d d d ƒd d t ƒ S(   s„   
        When L{MemCacheProtocol.checkAndSet} response is C{EXISTS}, the
        resulting L{Deferred} fires with C{False}.
        R   R   R•   R   s   cas foo 0 0 3 1234
bar
s   EXISTS
(   R   R   R–   R'   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   test_casUnknowKeyt  s    (   R=   R>   R?   RF   R   RR   RS   R_   Rb   Rc   Rd   Rj   Rk   Rl   Ru   R|   R   R‚   R„   R†   R‡   R‰   RŒ   R   RŽ   R   R‘   R“   R”   R—   R˜   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyR@   Þ   s:   																					
	
	
						t   CommandFailureTestsc           B   s    e  Z d  Z d „  Z d „  Z RS(   sZ   
    Tests for correct failure of commands on a disconnected
    L{MemCacheProtocol}.
    c         C   si   t  ƒ  |  _ t ƒ  |  _ |  j j |  j _ t ƒ  |  _ |  j |  j _ |  j j |  j ƒ |  j j	 ƒ  d S(   sU   
        Create a disconnected memcache client, using a deterministic clock.
        N(
   R   R   R   RA   RB   R   RC   RD   RE   Rs   (   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyRF   „  s    c         C   s   |  j  | t ƒ S(   sÈ   
        Implementation of C{_test} which checks that the command fails with
        C{RuntimeError} because the transport is disconnected. All the
        parameters except C{d} are ignored.
        (   R[   RO   (   R   R   R   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyR   ‘  s    (   R=   R>   R?   RF   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyR™   ~  s   	N(   R?   t   twisted.internet.errorR    t   twisted.protocols.memcacheR   R   R   R   t   twisted.trial.unittestR   t   twisted.test.proto_helpersR   t   twisted.internet.taskR   t   twisted.internet.deferR   R	   R
   R   R   R@   R™   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/test/test_memcache.pyt   <module>   s   Éÿ ¡