use of org.apache.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.
the class RedisProtocolTest method testAuthRedis.
@Test
public void testAuthRedis() {
// default db.index=0
Invoker<IDemoService> refer = PROTOCOL.refer(IDemoService.class, registryUrl.addParameter("max.idle", 10).addParameter("max.active", 20));
IDemoService demoService = this.PROXY.getProxy(refer);
String value = demoService.get("key");
assertThat(value, is(nullValue()));
demoService.set("key", "newValue");
value = demoService.get("key");
assertThat(value, is("newValue"));
demoService.delete("key");
value = demoService.get("key");
assertThat(value, is(nullValue()));
refer.destroy();
// change db.index=1
String password = "123456";
int database = 1;
this.registryUrl = this.registryUrl.setPassword(password).addParameter("db.index", database);
refer = PROTOCOL.refer(IDemoService.class, registryUrl.addParameter("max.idle", 10).addParameter("max.active", 20));
demoService = this.PROXY.getProxy(refer);
demoService.set("key", "newValue");
value = demoService.get("key");
assertThat(value, is("newValue"));
// jedis gets the result comparison
JedisPool pool = new JedisPool(new GenericObjectPoolConfig(), "localhost", registryUrl.getPort(), 2000, password, database, (String) null);
try (Jedis jedis = pool.getResource()) {
byte[] valueByte = jedis.get("key".getBytes());
Serialization serialization = ExtensionLoader.getExtensionLoader(Serialization.class).getExtension(this.registryUrl.getParameter(Constants.SERIALIZATION_KEY, "java"));
ObjectInput oin = serialization.deserialize(this.registryUrl, new ByteArrayInputStream(valueByte));
String actual = (String) oin.readObject();
assertThat(value, is(actual));
} catch (Exception e) {
Assertions.fail("jedis gets the result comparison is error!");
} finally {
pool.destroy();
}
demoService.delete("key");
value = demoService.get("key");
assertThat(value, is(nullValue()));
refer.destroy();
}
use of org.apache.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.
the class TransportCodec method decode.
@Override
public Object decode(Channel channel, ChannelBuffer buffer) throws IOException {
InputStream input = new ChannelBufferInputStream(buffer);
ObjectInput objectInput = getSerialization(channel).deserialize(channel.getUrl(), input);
Object object = decodeData(channel, objectInput);
if (objectInput instanceof Cleanable) {
((Cleanable) objectInput).cleanup();
}
return object;
}
use of org.apache.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.
the class AbstractSerializationTest method test_LinkedHashMap.
@Test
public void test_LinkedHashMap() throws Exception {
LinkedHashMap<String, String> data = new LinkedHashMap<String, String>();
data.put("1", "a");
data.put("2", "b");
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(data);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
Object read = deserialize.readObject();
assertTrue(read instanceof LinkedHashMap);
@SuppressWarnings("unchecked") String key1 = ((LinkedHashMap<String, String>) read).entrySet().iterator().next().getKey();
assertEquals("1", key1);
assertEquals(data, read);
try {
deserialize.readObject();
fail();
} catch (IOException expected) {
}
}
use of org.apache.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.
the class AbstractSerializationTest method test_Byte.
@Test
public void test_Byte() throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeByte((byte) 123);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
assertEquals((byte) 123, deserialize.readByte());
try {
deserialize.readByte();
fail();
} catch (IOException expected) {
}
}
use of org.apache.dubbo.common.serialize.ObjectInput in project dubbo by alibaba.
the class AbstractSerializationTest method test_MediaContent_WithType_badStream.
@Test
public void test_MediaContent_WithType_badStream() throws Exception {
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(mediaContent);
objectOutput.flushBuffer();
byte[] byteArray = byteArrayOutputStream.toByteArray();
for (int i = 0; i < byteArray.length; i++) {
if (i % 3 == 0) {
byteArray[i] = (byte) ~byteArray[i];
}
}
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
try {
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
// local variable, convenient for debug
@SuppressWarnings("unused") Object read = deserialize.readObject(MediaContent.class);
fail();
} catch (IOException expected) {
System.out.println(expected);
}
}
Aggregations