Java Code Examples for com.alipay.remoting.InvokeContext#clear()
The following examples show how to use
com.alipay.remoting.InvokeContext#clear() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassCustomSerializerTest.java From sofa-bolt with Apache License 2.0 | 6 votes |
/** * test custom serializer using invoke contxt in sync * * @throws Exception */ @Test public void testInvokeContextCustomSerializer_SYNC() throws Exception { NormalRequestBodyCustomSerializer_InvokeContext s1 = new NormalRequestBodyCustomSerializer_InvokeContext(); NormalStringCustomSerializer_InvokeContext s2 = new NormalStringCustomSerializer_InvokeContext(); CustomSerializerManager.registerCustomSerializer(RequestBody.class.getName(), s1); CustomSerializerManager.registerCustomSerializer(String.class.getName(), s2); RequestBody body = new RequestBody(1, "hello world!"); InvokeContext invokeContext = new InvokeContext(); invokeContext.putIfAbsent(NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE_KEY, NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE1_value); String ret = (String) client.invokeSync(addr, body, invokeContext, 1000); Assert.assertEquals(RequestBody.DEFAULT_SERVER_RETURN_STR + "RANDOM", ret); Assert.assertTrue(s1.isSerialized()); Assert.assertTrue(s1.isDeserialized()); invokeContext.clear(); invokeContext.putIfAbsent(NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE_KEY, NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE2_value); ret = (String) client.invokeSync(addr, body, invokeContext, 1000); Assert.assertEquals(NormalStringCustomSerializer_InvokeContext.UNIVERSAL_RESP, ret); Assert.assertTrue(s1.isSerialized()); Assert.assertTrue(s1.isDeserialized()); }
Example 2
Source File: BasicUsage_InvokeContext_Test.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testServerSyncUsingConnection() throws Exception { Connection clientConn = client.createStandaloneConnection(ip, port, 1000); for (int i = 0; i < invokeTimes; i++) { InvokeContext invokeContext = new InvokeContext(); RequestBody req1 = new RequestBody(1, RequestBody.DEFAULT_CLIENT_STR); String serverres = (String) client.invokeSync(clientConn, req1, invokeContext, 1000); Assert.assertEquals(serverres, RequestBody.DEFAULT_SERVER_RETURN_STR); Assert.assertNotNull(serverConnectProcessor.getConnection()); Connection serverConn = serverConnectProcessor.getConnection(); invokeContext.clear(); RequestBody req = new RequestBody(1, RequestBody.DEFAULT_SERVER_STR); String clientres = (String) server.getRpcServer().invokeSync(serverConn, req, invokeContext, 1000); Assert.assertEquals(clientres, RequestBody.DEFAULT_CLIENT_RETURN_STR); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_LOCAL_IP)); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_REMOTE_IP)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_LOCAL_PORT)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_REMOTE_PORT)); } Assert.assertTrue(serverConnectProcessor.isConnected()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(invokeTimes, serverUserProcessor.getInvokeTimes()); }
Example 3
Source File: BasicUsage_InvokeContext_Test.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testServerSyncUsingAddress() throws Exception { Connection clientConn = client.createStandaloneConnection(ip, port, 1000); String remote = RemotingUtil.parseRemoteAddress(clientConn.getChannel()); String local = RemotingUtil.parseLocalAddress(clientConn.getChannel()); logger.warn("Client say local:" + local); logger.warn("Client say remote:" + remote); for (int i = 0; i < invokeTimes; i++) { InvokeContext invokeContext = new InvokeContext(); RequestBody req1 = new RequestBody(1, RequestBody.DEFAULT_CLIENT_STR); String serverres = (String) client.invokeSync(clientConn, req1, invokeContext, 1000); Assert.assertEquals(serverres, RequestBody.DEFAULT_SERVER_RETURN_STR); invokeContext.clear(); Assert.assertNotNull(serverConnectProcessor.getConnection()); // only when client invoked, the remote address can be get by UserProcessor // otherwise, please use ConnectionEventProcessor String remoteAddr = serverUserProcessor.getRemoteAddr(); RequestBody req = new RequestBody(1, RequestBody.DEFAULT_SERVER_STR); String clientres = (String) server.getRpcServer().invokeSync(remoteAddr, req, invokeContext, 1000); Assert.assertEquals(clientres, RequestBody.DEFAULT_CLIENT_RETURN_STR); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_LOCAL_IP)); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_REMOTE_IP)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_LOCAL_PORT)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_REMOTE_PORT)); } Assert.assertTrue(serverConnectProcessor.isConnected()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(invokeTimes, serverUserProcessor.getInvokeTimes()); }
Example 4
Source File: BasicUsage_InvokeContext_Url_Test.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testServerSyncUsingConnection() throws Exception { Connection clientConn = client.createStandaloneConnection(ip, port, 1000); for (int i = 0; i < invokeTimes; i++) { InvokeContext invokeContext = new InvokeContext(); RequestBody req1 = new RequestBody(1, RequestBody.DEFAULT_CLIENT_STR); String serverres = (String) client.invokeSync(clientConn, req1, invokeContext, 1000); Assert.assertEquals(serverres, RequestBody.DEFAULT_SERVER_RETURN_STR); Assert.assertNotNull(serverConnectProcessor.getConnection()); Connection serverConn = serverConnectProcessor.getConnection(); invokeContext.clear(); RequestBody req = new RequestBody(1, RequestBody.DEFAULT_SERVER_STR); String clientres = (String) server.getRpcServer().invokeSync(serverConn, req, invokeContext, 1000); Assert.assertEquals(clientres, RequestBody.DEFAULT_CLIENT_RETURN_STR); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_LOCAL_IP)); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_REMOTE_IP)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_LOCAL_PORT)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_REMOTE_PORT)); } Assert.assertTrue(serverConnectProcessor.isConnected()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(invokeTimes, serverUserProcessor.getInvokeTimes()); }
Example 5
Source File: BasicUsage_InvokeContext_Url_Test.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testServerSyncUsingAddress() throws Exception { Connection clientConn = client.createStandaloneConnection(ip, port, 1000); String remote = RemotingUtil.parseRemoteAddress(clientConn.getChannel()); String local = RemotingUtil.parseLocalAddress(clientConn.getChannel()); logger.warn("Client say local:" + local); logger.warn("Client say remote:" + remote); for (int i = 0; i < invokeTimes; i++) { InvokeContext invokeContext = new InvokeContext(); RequestBody req1 = new RequestBody(1, RequestBody.DEFAULT_CLIENT_STR); String serverres = (String) client.invokeSync(clientConn, req1, invokeContext, 1000); Assert.assertEquals(serverres, RequestBody.DEFAULT_SERVER_RETURN_STR); invokeContext.clear(); Assert.assertNotNull(serverConnectProcessor.getConnection()); // only when client invoked, the remote address can be get by UserProcessor // otherwise, please use ConnectionEventProcessor String remoteAddr = serverUserProcessor.getRemoteAddr(); RequestBody req = new RequestBody(1, RequestBody.DEFAULT_SERVER_STR); String clientres = (String) server.getRpcServer().invokeSync(remoteAddr, req, invokeContext, 1000); Assert.assertEquals(clientres, RequestBody.DEFAULT_CLIENT_RETURN_STR); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_LOCAL_IP)); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_REMOTE_IP)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_LOCAL_PORT)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_REMOTE_PORT)); } Assert.assertTrue(serverConnectProcessor.isConnected()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(invokeTimes, serverUserProcessor.getInvokeTimes()); }
Example 6
Source File: BasicUsage_InvokeContext_resuable_Test.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testServerSyncUsingConnection() throws Exception { Connection clientConn = client.createStandaloneConnection(ip, port, 1000); for (int i = 0; i < invokeTimes; i++) { InvokeContext invokeContext = new InvokeContext(); invokeContext.put(TESTKEY, "TESTVALUE"); RequestBody req1 = new RequestBody(1, RequestBody.DEFAULT_CLIENT_STR); String serverres = (String) client.invokeSync(clientConn, req1, invokeContext, 1000); Assert.assertEquals(serverres, RequestBody.DEFAULT_SERVER_RETURN_STR); invokeContext.clear(); invokeContext.put(TESTKEY, "TESTVALUE"); Assert.assertNotNull(serverConnectProcessor.getConnection()); Connection serverConn = serverConnectProcessor.getConnection(); RequestBody req = new RequestBody(1, RequestBody.DEFAULT_SERVER_STR); String clientres = (String) server.getRpcServer().invokeSync(serverConn, req, invokeContext, 1000); Assert.assertEquals(clientres, RequestBody.DEFAULT_CLIENT_RETURN_STR); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_LOCAL_IP)); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_REMOTE_IP)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_LOCAL_PORT)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_REMOTE_PORT)); Assert.assertEquals(invokeContext.get(TESTKEY), "TESTVALUE"); } Assert.assertTrue(serverConnectProcessor.isConnected()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(invokeTimes, serverUserProcessor.getInvokeTimes()); }
Example 7
Source File: BasicUsage_InvokeContext_resuable_Test.java From sofa-bolt with Apache License 2.0 | 5 votes |
@Test public void testServerSyncUsingAddress() throws Exception { Connection clientConn = client.createStandaloneConnection(ip, port, 1000); String remote = RemotingUtil.parseRemoteAddress(clientConn.getChannel()); String local = RemotingUtil.parseLocalAddress(clientConn.getChannel()); logger.warn("Client say local:" + local); logger.warn("Client say remote:" + remote); for (int i = 0; i < invokeTimes; i++) { InvokeContext invokeContext = new InvokeContext(); invokeContext.put(TESTKEY, "TESTVALUE"); RequestBody req1 = new RequestBody(1, RequestBody.DEFAULT_CLIENT_STR); String serverres = (String) client.invokeSync(clientConn, req1, invokeContext, 1000); Assert.assertEquals(serverres, RequestBody.DEFAULT_SERVER_RETURN_STR); invokeContext.clear(); invokeContext.put(TESTKEY, "TESTVALUE"); Assert.assertNotNull(serverConnectProcessor.getConnection()); // only when client invoked, the remote address can be get by UserProcessor // otherwise, please use ConnectionEventProcessor String remoteAddr = serverUserProcessor.getRemoteAddr(); RequestBody req = new RequestBody(1, RequestBody.DEFAULT_SERVER_STR); String clientres = (String) server.getRpcServer().invokeSync(remoteAddr, req, invokeContext, 1000); Assert.assertEquals(clientres, RequestBody.DEFAULT_CLIENT_RETURN_STR); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_LOCAL_IP)); Assert.assertEquals("127.0.0.1", invokeContext.get(InvokeContext.SERVER_REMOTE_IP)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_LOCAL_PORT)); Assert.assertNotNull(invokeContext.get(InvokeContext.SERVER_REMOTE_PORT)); Assert.assertEquals(invokeContext.get(TESTKEY), "TESTVALUE"); } Assert.assertTrue(serverConnectProcessor.isConnected()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(invokeTimes, serverUserProcessor.getInvokeTimes()); }
Example 8
Source File: ClassCustomSerializerTest.java From sofa-bolt with Apache License 2.0 | 5 votes |
/** * test custom serializer using invoke contxt in future * @throws Exception */ @Test public void testInvokeContextCustomSerializer_FUTURE() throws Exception { NormalRequestBodyCustomSerializer_InvokeContext s1 = new NormalRequestBodyCustomSerializer_InvokeContext(); NormalStringCustomSerializer_InvokeContext s2 = new NormalStringCustomSerializer_InvokeContext(); CustomSerializerManager.registerCustomSerializer(RequestBody.class.getName(), s1); CustomSerializerManager.registerCustomSerializer(String.class.getName(), s2); RequestBody body = new RequestBody(1, "hello world!"); InvokeContext invokeContext = new InvokeContext(); invokeContext.putIfAbsent(NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE_KEY, NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE1_value); RpcResponseFuture future = client.invokeWithFuture(addr, body, invokeContext, 1000); String ret = (String) future.get(1000); Assert.assertEquals(RequestBody.DEFAULT_SERVER_RETURN_STR + "RANDOM", ret); Assert.assertTrue(s1.isSerialized()); Assert.assertTrue(s1.isDeserialized()); invokeContext.clear(); invokeContext.putIfAbsent(NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE_KEY, NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE2_value); future = client.invokeWithFuture(addr, body, invokeContext, 1000); ret = (String) future.get(1000); Assert.assertEquals(NormalStringCustomSerializer_InvokeContext.UNIVERSAL_RESP, ret); Assert.assertTrue(s1.isSerialized()); Assert.assertTrue(s1.isDeserialized()); }
Example 9
Source File: CustomSerializerCodecTest.java From sofa-bolt with Apache License 2.0 | 4 votes |
@Test public void testServerSyncUsingConnection() throws Exception { NormalRequestBodyCustomSerializer s1 = new NormalRequestBodyCustomSerializer(); NormalStringCustomSerializer s2 = new NormalStringCustomSerializer(); CustomSerializerManager.registerCustomSerializer(RequestBody.class.getName(), s1); CustomSerializerManager.registerCustomSerializer(String.class.getName(), s2); Connection clientConn = client.createStandaloneConnection(ip, port, 1000); for (int i = 0; i < invokeTimes; i++) { byte testCodec = (byte) i; InvokeContext invokeContext = new InvokeContext(); invokeContext.put(InvokeContext.BOLT_CUSTOM_SERIALIZER, testCodec); RequestBody req1 = new RequestBody(1, RequestBody.DEFAULT_CLIENT_STR); String serverres = (String) client.invokeSync(clientConn, req1, invokeContext, 1000); Assert.assertEquals(serverres, RequestBody.DEFAULT_SERVER_RETURN_STR + "RANDOM"); Assert.assertEquals(testCodec, s1.getContentSerializer()); Assert.assertEquals(testCodec, s2.getContentSerializer()); Assert.assertNotNull(serverConnectProcessor.getConnection()); Connection serverConn = serverConnectProcessor.getConnection(); invokeContext.clear(); invokeContext.put(InvokeContext.BOLT_CUSTOM_SERIALIZER, (byte) (testCodec + 1)); s1.reset(); s2.reset(); RequestBody req = new RequestBody(1, RequestBody.DEFAULT_SERVER_STR); String clientres = (String) server.getRpcServer().invokeSync(serverConn, req, invokeContext, 1000); Assert.assertEquals(clientres, RequestBody.DEFAULT_CLIENT_RETURN_STR + "RANDOM"); Assert.assertEquals(testCodec + 1, s1.getContentSerializer()); Assert.assertEquals(testCodec + 1, s2.getContentSerializer()); } Assert.assertTrue(serverConnectProcessor.isConnected()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(invokeTimes, serverUserProcessor.getInvokeTimes()); }
Example 10
Source File: CustomSerializerCodecTest.java From sofa-bolt with Apache License 2.0 | 4 votes |
@Test public void testServerSyncUsingAddress() throws Exception { NormalRequestBodyCustomSerializer s1 = new NormalRequestBodyCustomSerializer(); NormalStringCustomSerializer s2 = new NormalStringCustomSerializer(); CustomSerializerManager.registerCustomSerializer(RequestBody.class.getName(), s1); CustomSerializerManager.registerCustomSerializer(String.class.getName(), s2); Connection clientConn = client.createStandaloneConnection(ip, port, 1000); String remote = RemotingUtil.parseRemoteAddress(clientConn.getChannel()); String local = RemotingUtil.parseLocalAddress(clientConn.getChannel()); logger.warn("Client say local:" + local); logger.warn("Client say remote:" + remote); for (int i = 0; i < invokeTimes; i++) { byte testCodec = (byte) i; InvokeContext invokeContext = new InvokeContext(); invokeContext.put(InvokeContext.BOLT_CUSTOM_SERIALIZER, testCodec); RequestBody req1 = new RequestBody(1, RequestBody.DEFAULT_CLIENT_STR); String serverres = (String) client.invokeSync(clientConn, req1, invokeContext, 1000); Assert.assertEquals(serverres, RequestBody.DEFAULT_SERVER_RETURN_STR + "RANDOM"); Assert.assertEquals(testCodec, s1.getContentSerializer()); Assert.assertEquals(testCodec, s2.getContentSerializer()); invokeContext.clear(); invokeContext.put(InvokeContext.BOLT_CUSTOM_SERIALIZER, (byte) (testCodec + 1)); s1.reset(); s2.reset(); Assert.assertNotNull(serverConnectProcessor.getConnection()); // only when client invoked, the remote address can be get by UserProcessor // otherwise, please use ConnectionEventProcessor String remoteAddr = serverUserProcessor.getRemoteAddr(); RequestBody req = new RequestBody(1, RequestBody.DEFAULT_SERVER_STR); String clientres = (String) server.getRpcServer().invokeSync(remoteAddr, req, invokeContext, 1000); Assert.assertEquals(clientres, RequestBody.DEFAULT_CLIENT_RETURN_STR + "RANDOM"); Assert.assertEquals(testCodec + 1, s1.getContentSerializer()); Assert.assertEquals(testCodec + 1, s2.getContentSerializer()); } Assert.assertTrue(serverConnectProcessor.isConnected()); Assert.assertEquals(1, serverConnectProcessor.getConnectTimes()); Assert.assertEquals(invokeTimes, serverUserProcessor.getInvokeTimes()); }