Package org.apache.directmemory.test

Examples of org.apache.directmemory.test.Wine


    @Test
    public void writeRequestWithObject()
        throws Exception
    {
        Wine wine = new Wine();
        wine.setName( "Bordeaux" );

        Serializer serializer = SerializerFactory.createNewSerializer();

        DirectMemoryRequest dmRq =
            new DirectMemoryRequest().setKey( "101" ).setUpdate( true ).setExpiresIn( 123 ).setObject(
                wine ).setSerializer( serializer );
        String rq = DirectMemoryWriter.instance().generateJsonRequest( dmRq );
        log.info( "rq:" + rq );

        dmRq = DirectMemoryParser.instance().buildRequest( new ByteArrayInputStream( rq.getBytes() ) );
        assertNotNull( dmRq );

        assertEquals( "101", dmRq.getKey() );
        assertTrue( dmRq.isUpdate() );
        assertEquals( 123, dmRq.getExpiresIn() );

        wine = serializer.deserialize( dmRq.getCacheContent(), Wine.class );
        assertEquals( "Bordeaux", wine.getName() );

    }
View Full Code Here


    public void putAndGet()
        throws Exception
    {
        // START SNIPPET: client-put

        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );
        assertTrue( client.put( new DirectMemoryRequest<Wine>( "bordeaux", bordeaux ) ).isStored() );

        // END SNIPPET: client-put

        // START SNIPPET: client-get
        DirectMemoryRequest rq = new DirectMemoryRequest( "bordeaux", Wine.class );

        DirectMemoryResponse<Wine> response = client.retrieve( rq );

        assertTrue( response.isFound() );
        Wine wine = response.getResponse();
        // END SNIPPET: client-get
        assertEquals( "Bordeaux", wine.getName() );
        assertEquals( "very great wine", wine.getDescription() );
    }
View Full Code Here

    @Test
    public void putAndGetAndDelete()
        throws Exception
    {
        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );

        assertTrue( client.put( new DirectMemoryRequest<Wine>( "bordeaux", bordeaux ) ).isStored() );

        DirectMemoryResponse<Wine> response = client.retrieve( new DirectMemoryRequest( "bordeaux", Wine.class ) );

        assertTrue( response.isFound() );
        Wine wine = response.getResponse();
        assertEquals( "Bordeaux", wine.getName() );
        assertEquals( "very great wine", wine.getDescription() );

        // START SNIPPET: client-delete

        DirectMemoryResponse deleteResponse = client.delete( new DirectMemoryRequest<Wine>( "bordeaux" ) );
        assertTrue( deleteResponse.isDeleted() );
View Full Code Here

    public void putSmallExpiresAndGetNotFound()
        throws Exception
    {

        DirectMemoryResponse deleteResponse = client.delete( new DirectMemoryRequest<Wine>( "bordeaux" ) );
        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );

        DirectMemoryResponse<Wine> response =
            client.put( new DirectMemoryRequest<Wine>( "bordeaux", bordeaux ).setExpiresIn( 1000 ) );

        assertTrue( response.isStored() );

        assertTrue( response.getStoredSize() > 0 );

        DirectMemoryRequest rq = new DirectMemoryRequest( "bordeaux", Wine.class );

        response = client.retrieve( rq );

        assertTrue( response.isFound() );
        Wine wine = response.getResponse();

        assertEquals( "Bordeaux", wine.getName() );
        assertEquals( "very great wine", wine.getDescription() );

        Thread.sleep( 10001 );

        rq = new DirectMemoryRequest( "bordeaux", Wine.class );
View Full Code Here

        throws Exception
    {

        Serializer serializer = SerializerFactory.createNewSerializer();

        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );

        DirectMemoryRequest directMemoryRequest =
            new DirectMemoryRequest().setKey( "bordeaux" ).setCacheContent( serializer.serialize( bordeaux ) );

        String rq = writer.generateJsonRequest( directMemoryRequest );

        MockHttpServletRequest putRequest = new MockHttpServletRequest();

        putRequest.setContentType( MediaType.APPLICATION_JSON );

        putRequest.setServletPath( "cache" );

        putRequest.setPathInfo( "/bordeaux" );

        putRequest.setContent( rq.getBytes() );

        MockHttpServletResponse putResponse = new MockHttpServletResponse();

        directMemoryServlet.doPut( putRequest, putResponse );

        assertEquals( HttpServletResponse.SC_OK, putResponse.getStatus() );

        // now retrieve the content

        MockHttpServletRequest getRequest = new MockHttpServletRequest();

        getRequest.addHeader( "Accept", MediaType.APPLICATION_JSON );

        getRequest.setPathInfo( "/bordeaux" );

        MockHttpServletResponse getResponse = new MockHttpServletResponse();

        directMemoryServlet.doGet( getRequest, getResponse );

        assertEquals( HttpServletResponse.SC_OK, getResponse.getStatus() );

        assertEquals( MediaType.APPLICATION_JSON, getResponse.getContentType() );

        DirectMemoryResponse response =
            parser.buildResponse( new ByteArrayInputStream( getResponse.getContentAsByteArray() ) );

        Wine wineFromCache = serializer.deserialize( response.getCacheContent(), Wine.class );

        assertEquals( bordeaux.getName(), wineFromCache.getName() );
        assertEquals( bordeaux.getDescription(), wineFromCache.getDescription() );

    }
View Full Code Here

        throws Exception
    {

        Serializer serializer = SerializerFactory.createNewSerializer();

        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );

        DirectMemoryRequest directMemoryRequest =
            new DirectMemoryRequest().setKey( "bordeaux" ).setCacheContent(
                serializer.serialize( bordeaux ) ).setExpiresIn( 3 );
View Full Code Here

        throws Exception
    {

        Serializer serializer = SerializerFactory.createNewSerializer();

        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );

        DirectMemoryRequest directMemoryRequest =
            new DirectMemoryRequest().setKey( "bordeaux" ).setCacheContent( serializer.serialize( bordeaux ) );

        String rq = writer.generateJsonRequest( directMemoryRequest );

        MockHttpServletRequest putRequest = new MockHttpServletRequest();

        putRequest.setContentType( MediaType.APPLICATION_JSON );

        putRequest.setServletPath( "cache" );

        putRequest.setPathInfo( "/bordeaux" );

        putRequest.setContent( rq.getBytes() );

        MockHttpServletResponse putResponse = new MockHttpServletResponse();

        directMemoryServlet.doPut( putRequest, putResponse );

        assertEquals( HttpServletResponse.SC_OK, putResponse.getStatus() );

        // now retrieve the content

        MockHttpServletRequest getRequest = new MockHttpServletRequest();

        getRequest.addHeader( "Accept", MediaType.APPLICATION_JSON );

        getRequest.setPathInfo( "/bordeaux" );

        MockHttpServletResponse getResponse = new MockHttpServletResponse();

        directMemoryServlet.doGet( getRequest, getResponse );

        assertEquals( HttpServletResponse.SC_OK, getResponse.getStatus() );

        assertEquals( MediaType.APPLICATION_JSON, getResponse.getContentType() );

        DirectMemoryResponse response =
            parser.buildResponse( new ByteArrayInputStream( getResponse.getContentAsByteArray() ) );

        Wine wineFromCache = serializer.deserialize( response.getCacheContent(), Wine.class );

        assertEquals( bordeaux.getName(), wineFromCache.getName() );
        assertEquals( bordeaux.getDescription(), wineFromCache.getDescription() );

        // now delete the content

        MockHttpServletRequest deleteRq = new MockHttpServletRequest();
View Full Code Here

TOP

Related Classes of org.apache.directmemory.test.Wine

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.