@Test public void unmatchedDoesNotHang() throws Exception { ReplayManager replayManager = new VhsReplayManager(); File harFile = temporaryFolder.newFile(); Resources.asByteSource(getClass().getResource("/empty.har")).copyTo(Files.asByteSink(harFile)); ReplaySessionConfig config = ReplaySessionConfig.builder(temporaryFolder.getRoot().toPath()) .build(harFile); int numTrials = 12; URI url = URI.create("http: try (ReplaySessionControl ctrl = replayManager.start(config)) { HostAndPort proxyAddress = ctrl.getSocketAddress(); for (int i = 0; i < numTrials; i++) { System.out.format("[%2d] fetching %s%n", i + 1, url); ImmutableHttpResponse rsp = Tests.fetch(proxyAddress, url); String actual = rsp.data.asCharSource(StandardCharsets.UTF_8).read(); assertEquals("repsonse content", "404 Not Found", actual); } } }
@Override public ReplaySessionControl start(ReplaySessionConfig sessionConfig) throws IOException { EntryMatcher harEntryMatcher = buildHarEntryMatcher(sessionConfig); EntryMatcher compositeEntryMatcher = enhanceEntryMatcherFromConfig(harEntryMatcher, sessionConfig.replayServerConfig); List<ResponseInterceptor> interceptors = new ArrayList<>(); interceptors.addAll(buildInterceptorsForReplacements(sessionConfig.replayServerConfig.replacements)); interceptors.addAll(buildInterceptorsForTransforms(sessionConfig.replayServerConfig.responseHeaderTransforms)); int port = sessionConfig.port; VirtualHarServer vhs = createVirtualHarServer(port, sessionConfig.scratchDir, compositeEntryMatcher, interceptors, config.bmpResponseListener); VirtualHarServerControl ctrl = vhs.start(); Runnable stopListener = () -> { sessionConfig.serverTerminationCallbacks.forEach(c -> { c.terminated(null); }); }; return new VhsReplaySessionControl(ctrl, true, stopListener); }
VhsReplayManager implements ReplayManager { @Override public ReplaySessionControl start(ReplaySessionConfig sessionConfig) throws IOException { EntryMatcher harEntryMatcher = buildHarEntryMatcher(sessionConfig); EntryMatcher compositeEntryMatcher = enhanceEntryMatcherFromConfig(harEntryMatcher, sessionConfig.replayServerConfig); List<ResponseInterceptor> interceptors = new ArrayList<>(); interceptors.addAll(buildInterceptorsForReplacements(sessionConfig.replayServerConfig.replacements)); interceptors.addAll(buildInterceptorsForTransforms(sessionConfig.replayServerConfig.responseHeaderTransforms)); int port = sessionConfig.port; VirtualHarServer vhs = createVirtualHarServer(port, sessionConfig.scratchDir, compositeEntryMatcher, interceptors, config.bmpResponseListener); VirtualHarServerControl ctrl = vhs.start(); Runnable stopListener = () -> { sessionConfig.serverTerminationCallbacks.forEach(c -> { c.terminated(null); }); }; return new VhsReplaySessionControl(ctrl, true, stopListener); } }
VhsReplayManager implements ReplayManager { @Override public ReplaySessionControl start(ReplaySessionConfig sessionConfig) throws IOException { EntryMatcher harEntryMatcher = buildHarEntryMatcher(sessionConfig); EntryMatcher compositeEntryMatcher = enhanceEntryMatcherFromConfig(harEntryMatcher, sessionConfig.replayServerConfig); List<ResponseInterceptor> interceptors = new ArrayList<>(); interceptors.addAll(buildInterceptorsForReplacements(sessionConfig.replayServerConfig.replacements)); interceptors.addAll(buildInterceptorsForTransforms(sessionConfig.replayServerConfig.responseHeaderTransforms)); int port = sessionConfig.port; VirtualHarServer vhs = createVirtualHarServer(port, sessionConfig.scratchDir, compositeEntryMatcher, interceptors, config.bmpResponseListener); VirtualHarServerControl ctrl = vhs.start(); Runnable stopListener = () -> { sessionConfig.serverTerminationCallbacks.forEach(c -> { c.terminated(null); }); }; return new VhsReplaySessionControl(ctrl, true, stopListener); } VhsReplayManager();  VhsReplayManager(VhsReplayManagerConfig config); protected  VhsReplayManager(VhsReplayManagerConfig config, EntryMatcherFactory entryMatcherFactory); }
VhsReplayManager implements ReplayManager { @Override public ReplaySessionControl start(ReplaySessionConfig sessionConfig) throws IOException { EntryMatcher harEntryMatcher = buildHarEntryMatcher(sessionConfig); EntryMatcher compositeEntryMatcher = enhanceEntryMatcherFromConfig(harEntryMatcher, sessionConfig.replayServerConfig); List<ResponseInterceptor> interceptors = new ArrayList<>(); interceptors.addAll(buildInterceptorsForReplacements(sessionConfig.replayServerConfig.replacements)); interceptors.addAll(buildInterceptorsForTransforms(sessionConfig.replayServerConfig.responseHeaderTransforms)); int port = sessionConfig.port; VirtualHarServer vhs = createVirtualHarServer(port, sessionConfig.scratchDir, compositeEntryMatcher, interceptors, config.bmpResponseListener); VirtualHarServerControl ctrl = vhs.start(); Runnable stopListener = () -> { sessionConfig.serverTerminationCallbacks.forEach(c -> { c.terminated(null); }); }; return new VhsReplaySessionControl(ctrl, true, stopListener); } VhsReplayManager();  VhsReplayManager(VhsReplayManagerConfig config); protected  VhsReplayManager(VhsReplayManagerConfig config, EntryMatcherFactory entryMatcherFactory); @Override ReplaySessionControl start(ReplaySessionConfig sessionConfig); }
VhsReplayManager implements ReplayManager { @Override public ReplaySessionControl start(ReplaySessionConfig sessionConfig) throws IOException { EntryMatcher harEntryMatcher = buildHarEntryMatcher(sessionConfig); EntryMatcher compositeEntryMatcher = enhanceEntryMatcherFromConfig(harEntryMatcher, sessionConfig.replayServerConfig); List<ResponseInterceptor> interceptors = new ArrayList<>(); interceptors.addAll(buildInterceptorsForReplacements(sessionConfig.replayServerConfig.replacements)); interceptors.addAll(buildInterceptorsForTransforms(sessionConfig.replayServerConfig.responseHeaderTransforms)); int port = sessionConfig.port; VirtualHarServer vhs = createVirtualHarServer(port, sessionConfig.scratchDir, compositeEntryMatcher, interceptors, config.bmpResponseListener); VirtualHarServerControl ctrl = vhs.start(); Runnable stopListener = () -> { sessionConfig.serverTerminationCallbacks.forEach(c -> { c.terminated(null); }); }; return new VhsReplaySessionControl(ctrl, true, stopListener); } VhsReplayManager();  VhsReplayManager(VhsReplayManagerConfig config); protected  VhsReplayManager(VhsReplayManagerConfig config, EntryMatcherFactory entryMatcherFactory); @Override ReplaySessionControl start(ReplaySessionConfig sessionConfig);  }