use of org.webpieces.data.api.BufferCreationPool in project webpieces by deanhiller.
the class TestBeans method testIncomingDataAndDataSeperate.
@Test
public void testIncomingDataAndDataSeperate() {
HttpDummyRequest req = Requests.createPostRequest("/postArray2", "user.accounts[1].name", "Account2Name", "user.accounts[1].color", "green", "user.accounts[2].addresses[0].number", "56", "user.firstName", "D&D", "user.lastName", "Hiller", "user.fullName", "Dean Hiller");
DataWrapperGenerator dataGen = DataWrapperGeneratorFactory.createDataWrapperGenerator();
HttpParser parser = HttpParserFactory.createParser(new BufferCreationPool());
MarshalState state = parser.prepareToMarshal();
ByteBuffer buffer = parser.marshalToByteBuffer(state, req.getRequest());
DataWrapper d1 = dataGen.wrapByteBuffer(buffer);
ByteBuffer buf2 = parser.marshalToByteBuffer(state, req.getData());
DataWrapper data = dataGen.chainDataWrappers(d1, dataGen.wrapByteBuffer(buf2));
// Split the body in half
List<? extends DataWrapper> split = dataGen.split(data, data.getReadableSize() - 20);
http11Socket.sendBytes(split.get(0));
http11Socket.sendBytes(split.get(1));
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
UserDto user = mockSomeLib.getUser();
Assert.assertEquals("D&D", user.getFirstName());
Assert.assertEquals(3, user.getAccounts().size());
Assert.assertEquals("Account2Name", user.getAccounts().get(1).getName());
Assert.assertEquals(56, user.getAccounts().get(2).getAddresses().get(0).getNumber());
}
use of org.webpieces.data.api.BufferCreationPool in project webpieces by deanhiller.
the class IntegSingleRequest method createHttpClient.
public static Http2Socket createHttpClient(String id, boolean isHttp, InetSocketAddress addr) {
BufferPool pool2 = new BufferCreationPool();
HpackParser hpackParser = HpackParserFactory.createParser(pool2, false);
Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
ChannelManager mgr = factory.createMultiThreadedChanMgr("client", pool2, executor2);
InjectionConfig injConfig = new InjectionConfig(hpackParser);
String host = addr.getHostName();
int port = addr.getPort();
ForTestSslClientEngineFactory ssl = new ForTestSslClientEngineFactory();
SSLEngine engine = ssl.createSslEngine(host, port);
Http2Client client = Http2ClientFactory.createHttpClient(mgr, injConfig);
Http2Socket socket;
if (isHttp) {
socket = client.createHttpSocket(id);
} else {
socket = client.createHttpsSocket(id, engine);
}
return socket;
}
use of org.webpieces.data.api.BufferCreationPool in project webpieces by deanhiller.
the class IntegTestLocalhostThroughput method testSoTimeoutOnSocket.
public void testSoTimeoutOnSocket() throws InterruptedException {
Executor executor = Executors.newFixedThreadPool(10, new NamedThreadFactory("serverThread"));
BufferPool pool = new BufferCreationPool();
ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
ChannelManager mgr = factory.createMultiThreadedChanMgr("server", pool, executor);
AsyncServerManager serverMgr = AsyncServerMgrFactory.createAsyncServer(mgr);
AsyncServer server = serverMgr.createTcpServer(new AsyncConfig("tcpServer"), new IntegTestLocalhostServerListener());
server.start(new InetSocketAddress(8080));
BufferPool pool2 = new BufferCreationPool();
DataListener listener = new ClientDataListener(pool2, recorder);
Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
TCPChannel channel = createClientChannel(pool2, executor2);
//TCPChannel channel = createNettyChannel();
recorder.start();
CompletableFuture<Channel> connect = channel.connect(new InetSocketAddress(8080), listener);
connect.thenAccept(p -> runWriting(channel));
synchronized (this) {
this.wait();
}
}
use of org.webpieces.data.api.BufferCreationPool in project webpieces by deanhiller.
the class IntegTestClientNotRead method testSoTimeoutOnSocket.
public void testSoTimeoutOnSocket() throws InterruptedException {
BufferCreationPool pool = new BufferCreationPool();
AsyncServerManager serverMgr = AsyncServerMgrFactory.createAsyncServer("server", pool);
AsyncServer server = serverMgr.createTcpServer(new AsyncConfig("tcpServer"), new IntegTestClientNotReadListener());
server.start(new InetSocketAddress(8080));
BufferCreationPool pool2 = new BufferCreationPool();
ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
ChannelManager mgr = factory.createSingleThreadedChanMgr("client", pool2);
TCPChannel channel = mgr.createTCPChannel("clientChan");
log.info("client");
timer.schedule(new TimerTask() {
@Override
public void run() {
logBytesTxfrd();
}
}, 1000, 5000);
CompletableFuture<Channel> connect = channel.connect(new InetSocketAddress(8080), new ClientDataListener());
connect.thenAccept(p -> runWriting(channel));
Thread.sleep(1000000000);
}
use of org.webpieces.data.api.BufferCreationPool in project webpieces by deanhiller.
the class IntegTestClientToEchoServer method testSoTimeoutOnSocket.
public void testSoTimeoutOnSocket() throws InterruptedException {
runEchoServer();
BufferPool pool2 = new BufferCreationPool();
DataListener listener = new ClientDataListener(pool2, recorder);
Executor executor2 = Executors.newFixedThreadPool(10, new NamedThreadFactory("clientThread"));
TCPChannel channel = createClientChannel(pool2, executor2);
//TCPChannel channel = createNettyChannel();
recorder.start();
CompletableFuture<Channel> connect = channel.connect(new InetSocketAddress(4444), listener);
connect.thenAccept(p -> runWriting(channel));
synchronized (this) {
this.wait();
}
}
Aggregations