Package de.javakaffee.web.msm

Examples of de.javakaffee.web.msm.MemcachedBackupSession


    public void testReadValueIntoObject() throws Exception {
        final MemcachedBackupSessionManager manager = new MemcachedBackupSessionManager();
        manager.setContainer( new StandardContext() );
        final XStreamTranscoder transcoder = new XStreamTranscoder( manager );

        final MemcachedBackupSession session = manager.createEmptySession();
        session.setValid( true );
        session.setCreationTime( System.currentTimeMillis() );
        getField( StandardSession.class, "lastAccessedTime" ).set( session, System.currentTimeMillis() + 100 );
        session.setMaxInactiveInterval( 600 );

        session.setId( "foo" );

        session.setAttribute( "person1", createPerson( "foo bar", Gender.MALE, "foo.bar@example.org", "foo.bar@example.com" ) );
        session.setAttribute( "person2", createPerson( "bar baz", Gender.FEMALE, "bar.baz@example.org", "bar.baz@example.com" ) );

        final long start1 = System.nanoTime();
        transcoder.serializeAttributes( session, session.getAttributesInternal() );
        System.out.println("xstream-ser took " + (System.nanoTime() - start1)/1000);

        final long start2 = System.nanoTime();
        transcoder.serializeAttributes( session, session.getAttributesInternal() );
        System.out.println("xstream-ser took " + (System.nanoTime() - start2)/1000);
       
        final long start3 = System.nanoTime();
        final byte[] json = transcoder.serializeAttributes( session, session.getAttributesInternal() );
        final Map<String, Object> readValue = (Map<String, Object>) transcoder.deserializeAttributes( json );
        System.out.println("xstream-round took " + (System.nanoTime() - start3)/1000);

        //System.out.println( "Have json: " + new String(json) );
        assertEquals( readValue, session.getAttributesInternal() );

    }
View Full Code Here


        LOG.info( "found: " + foundPerson.toString() );
        TestUtils.assertDeepEquals( person, foundPerson );

        final TranscoderService transcoderService = new TranscoderService( createTranscoder( manager ) );

        final MemcachedBackupSession session = createSession( manager, "123456789" );
        session.setAttribute( "person", foundPerson );

        final byte[] data = transcoderService.serialize( session );
        final MemcachedBackupSession deserialized = transcoderService.deserialize( data, manager );

        final Person deserializedPerson = (Person) deserialized.getAttribute( "person" );
        TestUtils.assertDeepEquals( foundPerson, deserializedPerson );

    }
View Full Code Here

    @Nonnull
    protected SessionManager createSessionManager() {
        final SessionManager manager = mock( SessionManager.class );
        when( manager.getContainer() ).thenReturn( new StandardContext() ); // needed for createSession
        when( manager.getMemcachedSessionService() ).thenReturn(newMemcachedSessionService(manager));
        when( manager.newMemcachedBackupSession() ).thenReturn( new MemcachedBackupSession( manager ) );
        return manager;
    }
View Full Code Here

    protected MemcachedSessionService newMemcachedSessionService(final SessionManager manager) {
        return new MemcachedSessionService(manager);
    }

    private static MemcachedBackupSession createSession( final SessionManager manager, final String id ) {
        final MemcachedBackupSession session = manager.getMemcachedSessionService().createEmptySession();
        session.setId( id );
        session.setValid( true );
        return session;
    }
View Full Code Here

    }

    @Nonnull
    public static MemcachedBackupSession createSession( @Nonnull final MemcachedSessionService service ) {
        // return (MemcachedBackupSession) service.getManager().createSession( null );
        final MemcachedBackupSession session = service.createEmptySession();
        session.setNew( true );
        session.setValid( true );
        session.setCreationTime( System.currentTimeMillis() );
        session.setMaxInactiveInterval( 23 );
        session.setId( "foo-n1" );
        return session;
    }
View Full Code Here

    }

    @Test( enabled = true )
    public void testStringBufferAndStringBuilderFormat() throws Exception {
        final MemcachedBackupSession session = _manager.createEmptySession();
        session.setValid( true );

        session.setAttribute( "stringbuffer", new StringBuffer( "<string\n&buffer/>" ) );
        session.setAttribute( "stringbuilder", new StringBuilder( "<string\n&buffer/>" ) );

        System.out.println( new String( _transcoder.serializeAttributes( session, session.getAttributesInternal() ) ));

        final Map<String, Object> deserialized =
                _transcoder.deserializeAttributes( _transcoder.serializeAttributes( session, session.getAttributesInternal() ) );

        assertDeepEquals( deserialized, session.getAttributesInternal() );

    }
View Full Code Here

     *
     * @throws Exception
     */
    @Test( enabled = true )
    public void testMapWithIntConstructorOnly() throws Exception {
        final MemcachedBackupSession session = _manager.createEmptySession();
        session.setValid( true );

        final HashMapWithIntConstructorOnly map = new HashMapWithIntConstructorOnly( 5 );
        session.setAttribute( "map", map );

        System.out.println( new String( _transcoder.serializeAttributes( session, session.getAttributesInternal() ) ));

        final Map<String, Object> deserialized =
                _transcoder.deserializeAttributes( _transcoder.serializeAttributes( session, session.getAttributesInternal() ) );

        assertDeepEquals( deserialized, session.getAttributesInternal() );
        assertDeepEquals( deserialized.get( "map" ), map );

    }
View Full Code Here

     *
     * @throws Exception
     */
    @Test( enabled = true )
    public void testCurrency() throws Exception {
        final MemcachedBackupSession session = _manager.createEmptySession();
        session.setValid( true );

        final Currency orig = Currency.getInstance( "EUR" );
        session.setAttribute( "currency1", orig );
        session.setAttribute( "currency2", orig );

        final Map<String, Object> deserialized =
                _transcoder.deserializeAttributes( _transcoder.serializeAttributes( session, session.getAttributesInternal() ) );

        assertDeepEquals( deserialized, session.getAttributesInternal() );

        // Check that the transient field defaultFractionDigits is initialized correctly (that was the bug)
        final Currency currency1 = (Currency) deserialized.get( "currency1" );
        Assert.assertEquals( currency1.getCurrencyCode(), orig.getCurrencyCode() );
        Assert.assertEquals( currency1.getDefaultFractionDigits(), orig.getDefaultFractionDigits() );
View Full Code Here

     *
     * @throws Exception
     */
    @Test( enabled = true )
    public void testXMLSerializableSupport() throws Exception {
        final MemcachedBackupSession session = _manager.createEmptySession();
        session.setValid( true );

        final String attributeName = "myxmlserializable";
        session.setAttribute( attributeName, new MyXMLSerializable( Runtime.getRuntime() ) );

        final Map<String, Object> deserialized =
                _transcoder.deserializeAttributes( _transcoder.serializeAttributes( session, session.getAttributesInternal() ) );

        assertDeepEquals( deserialized, session.getAttributesInternal() );
        final MyXMLSerializable myXMLSerializable = (MyXMLSerializable) deserialized.get( attributeName );
        Assert.assertNotNull( myXMLSerializable.getRuntime(), "Transient field runtime should be initialized by XMLFormat" +
            " used due to implementation of XMLSerializable." );
    }
View Full Code Here

     *
     * @throws Exception
     */
    @Test( enabled = true )
    public void testJavaUtilCollectionsUnmodifiable() throws Exception {
        final MemcachedBackupSession session = _manager.createEmptySession();
        session.setValid( true );

        session.setAttribute( "unmodifiableList", Collections.unmodifiableList( new ArrayList<String>( Arrays.asList( "foo", "bar" ) ) ) );
        final HashMap<String, String> m = new HashMap<String, String>();
        m.put( "foo", "bar" );
        session.setAttribute( "unmodifiableList", Collections.unmodifiableMap( m ) );

        final Map<String, Object> deserialized =
                _transcoder.deserializeAttributes( _transcoder.serializeAttributes( session, session.getAttributesInternal() ) );

        assertDeepEquals( deserialized, session.getAttributesInternal() );
    }
View Full Code Here

TOP

Related Classes of de.javakaffee.web.msm.MemcachedBackupSession

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.