/** * {@inheritDoc} */ @Override public SessionAttributesTranscoder createTranscoder( final SessionManager manager ) { return new JavaSerializationTranscoder( manager ); }
/** * {@inheritDoc} */ @Override public byte[] serializeAttributes( final MemcachedBackupSession session, final ConcurrentMap<String, Object> attributes ) { if ( attributes == null ) { throw new NullPointerException( "Can't serialize null" ); } ByteArrayOutputStream bos = null; ObjectOutputStream oos = null; try { bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream( bos ); writeAttributes( session, attributes, oos ); return bos.toByteArray(); } catch ( final IOException e ) { throw new IllegalArgumentException( "Non-serializable object", e ); } finally { closeSilently( bos ); closeSilently( oos ); } }
try { bis = new ByteArrayInputStream( in ); ois = createObjectInputStream( bis ); throw new TranscoderDeserializationException( "Caught IOException decoding data", e ); } finally { closeSilently( bis ); closeSilently( ois );
@Test public void testSerializeSessionWithoutAttributes() { final MemcachedBackupSession session = (MemcachedBackupSession) _manager.createSession( null ); session.setLastBackupTime( System.currentTimeMillis() ); final TranscoderService transcoderService = new TranscoderService( new JavaSerializationTranscoder( _manager ) ); final byte[] data = transcoderService.serialize( session ); final MemcachedBackupSession deserialized = transcoderService.deserialize( data, _manager ); assertSessionFields( session, deserialized ); }
/** * {@inheritDoc} */ @Override public byte[] serializeAttributes( final MemcachedBackupSession session, final ConcurrentMap<String, Object> attributes ) { if ( attributes == null ) { throw new NullPointerException( "Can't serialize null" ); } ByteArrayOutputStream bos = null; ObjectOutputStream oos = null; try { bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream( bos ); writeAttributes( session, attributes, oos ); return bos.toByteArray(); } catch ( final IOException e ) { throw new IllegalArgumentException( "Non-serializable object", e ); } finally { closeSilently( bos ); closeSilently( oos ); } }
try { bis = new ByteArrayInputStream( in ); ois = createObjectInputStream( bis ); throw new TranscoderDeserializationException( "Caught IOException decoding data", e ); } finally { closeSilently( bis ); closeSilently( ois );
@Test public void testSerializeSessionWithAttributes() { final MemcachedBackupSession session = (MemcachedBackupSession) _manager.createSession( null ); final TranscoderService transcoderService = new TranscoderService( new JavaSerializationTranscoder( _manager ) ); final String value = "bar"; session.setAttribute( "foo", value ); session.setLastBackupTime( System.currentTimeMillis() ); final byte[] data = transcoderService.serialize( session ); final MemcachedBackupSession deserialized = transcoderService.deserialize( data, _manager ); assertSessionFields( session, deserialized ); Assert.assertEquals( value, deserialized.getAttribute( "foo" ) ); }
@BeforeMethod public void setUp(final Method testMethod) throws Throwable { couchbaseProvided = Boolean.parseBoolean(System.getProperty("couchbase.provided", "false")); final int couchbasePort = Integer.parseInt(System.getProperty("couchbase.port", "18091")); if(!couchbaseProvided) { cluster.add(setupCouchbase(couchbasePort)); } try { System.setProperty( "org.apache.catalina.startup.EXIT_ON_INIT_FAILURE", "true" ); _tomcat1 = getTestUtils().tomcatBuilder().port(_portTomcat1).memcachedNodes("http://localhost:"+ couchbasePort +"/pools") .sticky(true).memcachedProtocol("binary").username("default").buildAndStart(); } catch ( final Throwable e ) { LOG.error( "could not start tomcat.", e ); throw e; } setupCouchbaseClient(); transcoderService = new TranscoderService(new JavaSerializationTranscoder(_tomcat1.getManager())); }
@BeforeMethod public void setUp(final Method testMethod) throws Throwable { redisProvided = Boolean.parseBoolean(System.getProperty("redis.provided", "false")); final int redisPort = Integer.parseInt(System.getProperty("redis.port", "16379")); if (!redisProvided) { embeddedRedisServer = new RedisServer(redisPort); embeddedRedisServer.start(); } try { System.setProperty( "org.apache.catalina.startup.EXIT_ON_INIT_FAILURE", "true" ); _tomcat1 = getTestUtils().tomcatBuilder().port(_portTomcat1).memcachedNodes("redis://localhost:"+ redisPort) .sticky(true).buildAndStart(); } catch ( final Throwable e ) { LOG.error( "could not start tomcat.", e ); throw e; } redisClient = new BinaryJedis("localhost", redisPort); transcoderService = new TranscoderService(new JavaSerializationTranscoder(_tomcat1.getManager())); }
/** * {@inheritDoc} */ @Override public SessionAttributesTranscoder createTranscoder( final SessionManager manager ) { return new JavaSerializationTranscoder( manager ); }
_service.setLockingMode(LockingMode.ALL.name()); final TranscoderService transcoderService = new TranscoderService(new JavaSerializationTranscoder()); _service.setTranscoderService( transcoderService );