You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Ulrich Kramer (JIRA)" <ji...@apache.org> on 2013/04/17 13:57:15 UTC

[jira] [Created] (CAMEL-6294) StreamCache doesn't work as expected

Ulrich Kramer created CAMEL-6294:
------------------------------------

             Summary: StreamCache doesn't work as expected
                 Key: CAMEL-6294
                 URL: https://issues.apache.org/jira/browse/CAMEL-6294
             Project: Camel
          Issue Type: Bug
          Components: camel-core
    Affects Versions: 2.10.4
         Environment: Debian 6.0
            Reporter: Ulrich Kramer
             Fix For: 2.10.5


The following Unittests fail:


{code}
package com.sap.camel.util;

import java.io.InputStream;

import junit.framework.Assert;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.converter.stream.CachedOutputStream;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.DefaultExchange;
import org.testng.annotations.Test;

public class StreamCacheBugs {
	
	private CamelContext context;
	public void setUp() {
		
		context = new DefaultCamelContext();
	}

	@Test
	public void multipleConvertionsYielsToEmptyBody() throws Exception {
		Exchange exchange = new DefaultExchange(context);
		Message msg = exchange.getIn();
		CachedOutputStream out = new CachedOutputStream(exchange);
		out.write("Hello World".getBytes());
		msg.setBody(out.getStreamCache());
		Assert.assertEquals(msg.getBody(String.class), "Hello World");
		Assert.assertEquals(msg.getBody(String.class), "Hello World");

	}

	@Test
	public void closingInputStreamYieldsToException() throws Exception {
		Exchange exchange = new DefaultExchange(context);
		Message msg = exchange.getIn();
		CachedOutputStream out = new CachedOutputStream(exchange);
		for ( int i = 0 ; i < 10000; i++) out.write("0123456789".getBytes());
		msg.setBody(out.getStreamCache());
		InputStream in = msg.getBody(InputStream.class);
		in.read();
		in.close();
		msg.getBody(String.class);

	}
	
	@Test
	public void cachedOutputStreamsShouldBeClosable() throws Exception {
		Exchange exchange = new DefaultExchange(context);
		Message msg = exchange.getIn();
		CachedOutputStream out = new CachedOutputStream(exchange);
		for ( int i = 0 ; i < 10000; i++) out.write("0123456789".getBytes());
		msg.setBody(out.getStreamCache());
		out.close();
		msg.getBody(String.class);
	}

}
{code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira