Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Tape files not writing to disk - java, junit, spring, Apache HttpClient, log4j #74

Closed
nwest1 opened this Issue · 3 comments

2 participants

@nwest1

After getting the proxy properly hooked in, I can step through the Betamax code and see that a tape should be written out. Due to my poor groovy skills, I'm not sure how to figure out why.

I can see the request/response in memory, but when a test completes, the .yaml file isn't written out to disk. Default tape directories are created.

Is there a better way to troubleshoot this or has anyone encountered this before?

Regards,
Nathan

@robfletcher
Owner

Can you attach an example that reproduces the problem?

Are you using Betamax in a test/spec or are you doing something different?

@nwest1

I'm using it in a test.

http://dl.dropbox.com/u/57153162/BetamaxTest.tar.gz

The link is an eclipse project. Sorry it's not more pared down, but I was going off my existing unit tests.

I've tried to set the proxy in a few different ways, but none of them seem to work.

I've set the http.proxyHost/port at the eclipse startup level, in the eclipse network connections, as VM args for running the junit tests and as illustrated below. Hope you can shed some light.

Thanks!

Here's the test:

package test;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.log4j.Logger;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import co.freeside.betamax.Betamax;
import co.freeside.betamax.Recorder;
import co.freeside.betamax.httpclient.BetamaxRoutePlanner;

@RunWith(SpringJUnit4ClassRunner.class)
public class TestThis {

    @Rule public Recorder recorder = new Recorder();

    final static Logger LOG = Logger.getLogger(TestThis.class.getName());

    @Betamax(tape="Test")
    @Test
    public void testBlah() {
        System.setProperty("http.proxyHost", "192.168.1.49");
        System.setProperty("http.proxyPort", "5555");
        DefaultHttpClient client = new DefaultHttpClient();

        BetamaxRoutePlanner.configure(client);

        HttpGet request = new HttpGet("http://google.com");

        try {
            HttpResponse response = client.execute(request);
        } catch (Exception e) {
            System.out.println(e);
        }
    }

}

Log:

19:43:49,818 DEBUG t.context.junit4.SpringJUnit4ClassRunner: 106 - SpringJUnit4ClassRunner constructor called with [class test.TestThis].
19:43:49,830  INFO springframework.test.context.TestContext:  91 - @ContextConfiguration not found for class [class test.TestThis]
19:43:49,833  INFO ramework.test.context.TestContextManager: 185 - @TestExecutionListeners is not present for class [class test.TestThis]: using defaults.
19:43:49,836 DEBUG ramework.test.context.TestContextManager: 230 - Could not instantiate default TestExecutionListener class [org.springframework.test.context.support.DependencyInjectionTestExecutionListener]. Specify custom listener classes or make the default listener classes available.
19:43:49,836 DEBUG ramework.test.context.TestContextManager: 230 - Could not instantiate default TestExecutionListener class [org.springframework.test.context.support.DirtiesContextTestExecutionListener]. Specify custom listener classes or make the default listener classes available.
19:43:49,836 DEBUG ramework.test.context.TestContextManager: 230 - Could not instantiate default TestExecutionListener class [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes available.
19:43:49,842 DEBUG mework.test.annotation.ProfileValueUtils:  68 - Retrieved @ProfileValueSourceConfiguration [null] for test class [test.TestThis]
19:43:49,843 DEBUG mework.test.annotation.ProfileValueUtils:  80 - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [test.TestThis]
19:43:49,844 DEBUG mework.test.annotation.ProfileValueUtils:  68 - Retrieved @ProfileValueSourceConfiguration [null] for test class [test.TestThis]
19:43:49,844 DEBUG mework.test.annotation.ProfileValueUtils:  80 - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [test.TestThis]
19:43:49,845 DEBUG mework.test.annotation.ProfileValueUtils:  68 - Retrieved @ProfileValueSourceConfiguration [null] for test class [test.TestThis]
19:43:49,845 DEBUG mework.test.annotation.ProfileValueUtils:  80 - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [test.TestThis]
19:43:49,849 DEBUG mework.test.annotation.ProfileValueUtils:  68 - Retrieved @ProfileValueSourceConfiguration [null] for test class [test.TestThis]
19:43:49,849 DEBUG mework.test.annotation.ProfileValueUtils:  80 - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [test.TestThis]
2013-01-10 19:43:50.825:INFO::jetty-7.3.1.v20110307
2013-01-10 19:43:50.856:INFO::Started SelectChannelConnector@0.0.0.0:5555
2013-01-10 19:43:51.038:INFO::Started SslSelectChannelConnector@0.0.0.0:5556
19:43:51,206 DEBUG p.impl.conn.BasicClientConnectionManager: 159 - Get connection for route {}->http://192.168.1.49:5555->http://google.com
19:43:51,216 DEBUG mpl.conn.DefaultClientConnectionOperator: 177 - Connecting to 192.168.1.49:5555
19:43:51,241 DEBUG e.http.client.protocol.RequestAddCookies: 132 - CookieSpec selected: best-match
19:43:51,255 DEBUG he.http.client.protocol.RequestAuthCache:  78 - Auth cache not set in the context
19:43:51,255 DEBUG ent.protocol.RequestTargetAuthentication:  78 - Target auth state: UNCHALLENGED
19:43:51,256 DEBUG ient.protocol.RequestProxyAuthentication:  87 - Proxy auth state: UNCHALLENGED
19:43:51,256 DEBUG pache.http.impl.client.DefaultHttpClient: 710 - Attempt 1 to execute request
19:43:51,257 DEBUG e.http.impl.conn.DefaultClientConnection: 269 - Sending request: GET http://google.com HTTP/1.1
19:43:51,257 DEBUG                     org.apache.http.wire:  63 - >> "GET http://google.com HTTP/1.1[\r][\n]"
19:43:51,259 DEBUG                     org.apache.http.wire:  63 - >> "Host: google.com[\r][\n]"
19:43:51,259 DEBUG                     org.apache.http.wire:  63 - >> "Proxy-Connection: Keep-Alive[\r][\n]"
19:43:51,260 DEBUG                     org.apache.http.wire:  63 - >> "User-Agent: Apache-HttpClient/4.2.2 (java 1.5)[\r][\n]"
19:43:51,260 DEBUG                     org.apache.http.wire:  63 - >> "[\r][\n]"
19:43:51,261 DEBUG                  org.apache.http.headers: 273 - >> GET http://google.com HTTP/1.1
19:43:51,261 DEBUG                  org.apache.http.headers: 276 - >> Host: google.com
19:43:51,261 DEBUG                  org.apache.http.headers: 276 - >> Proxy-Connection: Keep-Alive
19:43:51,261 DEBUG                  org.apache.http.headers: 276 - >> User-Agent: Apache-HttpClient/4.2.2 (java 1.5)
19:43:51,297 DEBUG                     org.apache.http.wire:  63 - << "HTTP/1.1 400 Bad Request[\r][\n]"
19:43:51,299 DEBUG                     org.apache.http.wire:  63 - << "Cache-Control: must-revalidate,no-cache,no-store[\r][\n]"
19:43:51,299 DEBUG                     org.apache.http.wire:  63 - << "Content-Type: text/html;charset=ISO-8859-1[\r][\n]"
19:43:51,299 DEBUG                     org.apache.http.wire:  63 - << "Content-Length: 1274[\r][\n]"
19:43:51,300 DEBUG                     org.apache.http.wire:  63 - << "Server: Jetty(7.3.1.v20110307)[\r][\n]"
19:43:51,300 DEBUG                     org.apache.http.wire:  63 - << "[\r][\n]"
19:43:51,301 DEBUG e.http.impl.conn.DefaultClientConnection: 254 - Receiving response: HTTP/1.1 400 Bad Request
19:43:51,302 DEBUG                  org.apache.http.headers: 257 - << HTTP/1.1 400 Bad Request
19:43:51,302 DEBUG                  org.apache.http.headers: 260 - << Cache-Control: must-revalidate,no-cache,no-store
19:43:51,302 DEBUG                  org.apache.http.headers: 260 - << Content-Type: text/html;charset=ISO-8859-1
19:43:51,303 DEBUG                  org.apache.http.headers: 260 - << Content-Length: 1274
19:43:51,303 DEBUG                  org.apache.http.headers: 260 - << Server: Jetty(7.3.1.v20110307)
19:43:51,307 DEBUG pache.http.impl.client.DefaultHttpClient: 540 - Connection can be kept alive indefinitely
2013-01-10 19:43:51.417:WARN::1 threads could not be stopped

@robfletcher
Owner

Ah, you're getting bitten by #61 if you change the URL you're requesting to http://google.com/ (note trailing /) the tape is written out.

Also, you do not need to explicitly set the proxy system properties - Betamax does that for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.