use of net.morimekta.providence.serializer.DefaultSerializerProvider in project providence by morimekta.
the class HttpClientHandlerNetworkTest method setUp.
@Before
public void setUp() throws Exception {
executorService = Executors.newSingleThreadExecutor();
provider = new DefaultSerializerProvider();
serverSocket = new ServerSocket();
serverSocket.bind(new InetSocketAddress("localhost", 0));
port = serverSocket.getLocalPort();
serverSocket.setSoTimeout(200);
flag = new AtomicBoolean(true);
executorService.submit(() -> {
while (flag.get()) {
try {
Socket socket = serverSocket.accept();
Thread.sleep(10L);
// Do not read request.
socket.getOutputStream().write(("HTTP/1.1 403 Unauthorized\r\n" + "\r\n").getBytes(StandardCharsets.UTF_8));
socket.close();
} catch (SocketTimeoutException e) {
// ignore
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
try {
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
});
}
use of net.morimekta.providence.serializer.DefaultSerializerProvider in project providence by morimekta.
the class HttpClientHandlerTest method setUp.
@Before
public void setUp() throws Exception {
Awaitility.setDefaultPollDelay(50, TimeUnit.MILLISECONDS);
Log.setLog(new NoLogging());
impl = mock(net.morimekta.test.thrift.client.TestService.Iface.class);
TProcessor processor = new net.morimekta.test.thrift.client.TestService.Processor<>(impl);
instrumentation = mock(ServiceCallInstrumentation.class);
provider = new DefaultSerializerProvider();
server = new Server(0);
ServletContextHandler handler = new ServletContextHandler();
handler.addServlet(new ServletHolder(new TServlet(processor, new TBinaryProtocol.Factory())), "/" + ENDPOINT);
handler.addServlet(new ServletHolder(new HttpServlet() {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}), "/" + NOT_FOUND);
handler.addServlet(new ServletHolder(new HttpServlet() {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentType("text/html");
resp.getWriter().print("<html></html>");
}
}), "/" + HTML);
handler.addServlet(new ServletHolder(new HttpServlet() {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setStatus(HttpServletResponse.SC_OK);
Serializer serializer = provider.getDefault();
resp.setContentType(serializer.mediaType());
serializer.serialize(resp.getOutputStream(), reply.get());
}
}), "/" + RESPONSE);
contentTypes = new ArrayList<>();
reply = new AtomicReference<>();
server.setHandler(handler);
server.setRequestLog((request, response) -> contentTypes.addAll(Collections.list(request.getHeaders("Content-Type")).stream().map(Object::toString).collect(Collectors.toList())));
server.start();
port = getExposedPort(server);
}
use of net.morimekta.providence.serializer.DefaultSerializerProvider in project providence by morimekta.
the class ProvidenceServletTest method setUpServer.
@Before
public void setUpServer() throws Exception {
Awaitility.setDefaultPollDelay(2, TimeUnit.MILLISECONDS);
Log.setLog(new NoLogging());
impl = mock(TestService.Iface.class);
instrumentation = mock(ServiceCallInstrumentation.class);
provider = new DefaultSerializerProvider();
server = new Server(0);
ServletContextHandler handler = new ServletContextHandler();
handler.addServlet(new ServletHolder(new ProvidenceServlet(new TestService.Processor(impl), provider, instrumentation)), "/" + ENDPOINT);
server.setHandler(handler);
server.start();
port = getExposedPort(server);
}
use of net.morimekta.providence.serializer.DefaultSerializerProvider in project providence by morimekta.
the class RPCProvidenceHttpTest method setUp.
@Before
public void setUp() throws Exception {
Log.setLog(new NoLogging());
rc = copyResourceTo("/pvdrc", temp.getRoot());
copyResourceTo("/test.thrift", temp.getRoot());
impl = mock(MyService.Iface.class);
server = new Server(0);
DefaultSerializerProvider provider = new DefaultSerializerProvider();
ServletContextHandler handler = new ServletContextHandler();
handler.addServlet(new ServletHolder(new ProvidenceServlet(new MyService.Processor(impl), provider)), "/" + ENDPOINT);
server.setHandler(handler);
server.start();
port = getExposedPort(server);
Thread.sleep(1);
exitCode = 0;
rpc = new RPC(console.tty()) {
@Override
protected void exit(int i) {
exitCode = i;
}
};
}
use of net.morimekta.providence.serializer.DefaultSerializerProvider in project providence by morimekta.
the class ProvidenceServlet_ThriftClientTest method setUpServer.
@BeforeClass
public static void setUpServer() throws Exception {
Awaitility.setDefaultPollDelay(2, TimeUnit.MILLISECONDS);
Log.setLog(new NoLogging());
impl = mock(TestService.Iface.class);
instrumentation = mock(ServiceCallInstrumentation.class);
provider = new DefaultSerializerProvider();
server = new Server(0);
ServletContextHandler handler = new ServletContextHandler();
handler.addServlet(new ServletHolder(new ProvidenceServlet(new TestService.Processor(impl), provider, instrumentation)), "/" + ENDPOINT);
server.setHandler(handler);
server.start();
port = getExposedPort(server);
}
Aggregations