use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.
the class LengthPrefixedCodecTest method testWrite$Twice.
@Test
public void testWrite$Twice() throws Exception {
final Buffer value1 = Buffer.ascii("TESTDATA");
final Buffer value2 = Buffer.ascii("TESTDATA");
codec.write(value1);
final BufferState state = codec.write(value2);
assertEquals(BufferState.NOT_EMPTY, state);
assertEquals(false, codec.full());
assertEquals(false, codec.empty());
assertEquals(0l, codec.getWriteCounter());
}
use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.
the class LengthPrefixedCodecTest method testWrite.
@Test
public void testWrite() throws Exception {
final Buffer value = Buffer.ascii("TESTDATA");
final BufferState state = codec.write(value);
assertEquals(BufferState.WAS_EMPTY, state);
assertEquals(false, codec.full());
assertEquals(false, codec.empty());
assertEquals(0l, codec.getWriteCounter());
}
use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.
the class LengthPrefixedCodecTest method testFlush$Partially.
@Test
public void testFlush$Partially() throws Exception {
final Buffer value = Buffer.ascii("TESTDATA");
codec.write(value);
final int bytesThatWillBeWritten = value.length() / 2;
expect(writableByteChannel.write((ByteBuffer) anyObject())).andAnswer(createWriteAnswer(bytesThatWillBeWritten));
replay(writableByteChannel);
final BufferState state = codec.flush();
assertEquals(BufferState.NOT_EMPTY, state);
assertEquals(false, codec.full());
assertEquals(false, codec.empty());
assertEquals(bytesThatWillBeWritten, codec.getWriteCounter());
}
use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.
the class LengthPrefixedCodecTest method testFlush.
@Test
public void testFlush() throws Exception {
final Buffer value = Buffer.ascii("TESTDATA");
codec.write(value);
final int bytesThatWillBeWritten = value.length();
expect(writableByteChannel.write((ByteBuffer) anyObject())).andAnswer(createWriteAnswer(bytesThatWillBeWritten));
replay(writableByteChannel);
final BufferState state = codec.flush();
assertEquals(BufferState.EMPTY, state);
assertEquals(false, codec.full());
assertEquals(true, codec.empty());
assertEquals(bytesThatWillBeWritten, codec.getWriteCounter());
assertEquals(BufferState.WAS_EMPTY, codec.flush());
}
use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.
the class ClientInvokerImpl method getMethodData.
private MethodData getMethodData(Method method) throws IOException {
MethodData rc = null;
synchronized (method_cache) {
rc = method_cache.get(method);
}
if (rc == null) {
StringBuilder sb = new StringBuilder();
sb.append(method.getName());
sb.append(",");
Class<?>[] types = method.getParameterTypes();
for (int i = 0; i < types.length; i++) {
if (i != 0) {
sb.append(",");
}
sb.append(encodeClassName(types[i]));
}
Buffer signature = new UTF8Buffer(sb.toString()).buffer();
Serialization annotation = method.getAnnotation(Serialization.class);
SerializationStrategy serializationStrategy;
if (annotation != null) {
serializationStrategy = serializationStrategies.get(annotation.value());
if (serializationStrategy == null) {
throw new RuntimeException("Could not find the serialization strategy named: " + annotation.value());
}
} else {
serializationStrategy = ObjectSerializationStrategy.INSTANCE;
}
final InvocationStrategy strategy;
if (AsyncInvocationStrategy.isAsyncMethod(method)) {
strategy = AsyncInvocationStrategy.INSTANCE;
} else {
strategy = BlockingInvocationStrategy.INSTANCE;
}
rc = new MethodData(strategy, serializationStrategy, signature);
synchronized (method_cache) {
method_cache.put(method, rc);
}
}
return rc;
}
Aggregations