use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class InvocationTest method testInvoke.
@Test(timeout = 30 * 1000)
public void testInvoke() throws Exception {
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
try {
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return new HelloImpl();
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
assertEquals("Hello Fabric!", hello.hello("Fabric"));
assertEquals("Hello World!", hello.helloworld());
// Verification the we can pick the right overloaded method even if using a mixure
// of primitives / objects and array dimensions.
assertEquals('a', hello.mix(0));
assertEquals('b', hello.mix(new int[] { 0 }));
assertEquals('c', hello.mix(new Integer(0)));
assertEquals('d', hello.mix(new Integer[] { new Integer(0) }));
assertEquals('e', hello.mix(new int[0][0]));
assertEquals('f', hello.mix(new Integer[0][0]));
AsyncCallbackFuture<String> future1 = new AsyncCallbackFuture<String>();
hello.hello("Hiram", future1);
assertEquals("Hello Hiram!", future1.get(2, TimeUnit.SECONDS));
assertEquals("Hello Hiram!", hello.protobuf(stringValue("Hiram")).getValue());
AsyncCallbackFuture<StringValue.Getter> future2 = new AsyncCallbackFuture<StringValue.Getter>();
hello.protobuf(stringValue("Hiram Async"), future2);
assertEquals("Hello Hiram Async!", future2.get(2, TimeUnit.SECONDS).getValue());
} finally {
server.stop();
client.stop();
}
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class ServerInvokerImpl method onCommand.
protected void onCommand(final Transport transport, Object data) {
try {
final DataByteArrayInputStream bais = new DataByteArrayInputStream((Buffer) data);
final int size = bais.readInt();
final long correlation = bais.readVarLong();
// Use UTF8Buffer instead of string to avoid encoding/decoding UTF-8 strings
// for every request.
final UTF8Buffer service = readBuffer(bais).utf8();
final Buffer encoded_method = readBuffer(bais);
final ServiceFactoryHolder holder = holders.get(service);
final MethodData methodData = holder.getMethodData(encoded_method);
final Object svc = holder.factory.get();
Runnable task = new Runnable() {
public void run() {
final DataByteArrayOutputStream baos = new DataByteArrayOutputStream();
try {
// make space for the size field.
baos.writeInt(0);
baos.writeVarLong(correlation);
} catch (IOException e) {
// should not happen
throw new RuntimeException(e);
}
// Lets decode the remaining args on the target's executor
// to take cpu load off the
methodData.invocationStrategy.service(methodData.serializationStrategy, holder.loader, methodData.method, svc, bais, baos, new Runnable() {
public void run() {
holder.factory.unget();
final Buffer command = baos.toBuffer();
// Update the size field.
BufferEditor editor = command.buffer().bigEndianEditor();
editor.writeInt(command.length);
queue().execute(new Runnable() {
public void run() {
transport.offer(command);
}
});
}
});
}
};
Executor executor;
if (svc instanceof Dispatched) {
executor = ((Dispatched) svc).queue();
} else {
executor = blockingExecutor;
}
executor.execute(task);
} catch (Exception e) {
LOGGER.info("Error while reading request", e);
}
}
use of io.fabric8.patch.Service in project jointware by isdream.
the class KubernetesKeyValueStyleGeneratorTest method testKubernetesWithAllKind.
protected static void testKubernetesWithAllKind() throws Exception {
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ServiceAccount());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ThirdPartyResource());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ResourceQuota());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Node());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ConfigMap());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new NetworkPolicy());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new CustomResourceDefinition());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Ingress());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Service());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Namespace());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Secret());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new LimitRange());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Event());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new PersistentVolume());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new StatefulSet());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new PersistentVolumeClaim());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new DaemonSet());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new HorizontalPodAutoscaler());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Pod());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ReplicaSet());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Job());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ReplicationController());
info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Deployment());
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class Logs method newInstance.
public static LogEvent newInstance(PaxLoggingEvent event) {
LogEvent answer = new LogEvent();
try {
answer.setLevel(toString(event.getLevel()));
} catch (NoClassDefFoundError error) {
// ENTESB-2234, KARAF-3350: Ignore NoClassDefFoundError exceptions
// Those exceptions may happen if the underlying pax-logging service
// bundle has been refreshed somehow.
answer.setLevel("LOG");
}
answer.setMessage(event.getMessage());
answer.setLogger(event.getLoggerName());
answer.setTimestamp(new Date(event.getTimeStamp()));
answer.setThread(event.getThreadName());
answer.setException(addMavenCoord(event.getThrowableStrRep()));
Map eventProperties = event.getProperties();
if (eventProperties != null && eventProperties.size() > 0) {
Map<String, String> properties = new HashMap<String, String>();
Set<Map.Entry> set = eventProperties.entrySet();
for (Map.Entry entry : set) {
Object key = entry.getKey();
Object value = entry.getValue();
if (key != null && value != null) {
properties.put(toString(key), toString(value));
}
}
MavenCoordinates.addMavenCoord(properties);
answer.setProperties(properties);
}
// event.getFQNOfLoggerClass()
try {
PaxLocationInfo locationInformation = event.getLocationInformation();
if (locationInformation != null) {
answer.setClassName(locationInformation.getClassName());
answer.setFileName(locationInformation.getFileName());
answer.setMethodName(locationInformation.getMethodName());
answer.setLineNumber(locationInformation.getLineNumber());
}
} catch (NoClassDefFoundError error) {
// ENTESB-2234, KARAF-3350: Ignore NoClassDefFoundError exceptions
}
return answer;
}
use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.
the class ExampleCxfProfileLongTest method testExample.
@Test
public void testExample() throws Exception {
System.out.println("creating the cxf-server container.");
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
try {
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy).withName("child").withProfiles("example-cxf-cxf.server").assertProvisioningResult().build();
try {
assertTrue("We should create the cxf-server container.", containers.size() == 1);
System.out.println("created the cxf-server container.");
// install bundle of CXF
Thread.sleep(2000);
System.out.println(executeCommand("fabric:cluster-list"));
// install bundle of CXF
Thread.sleep(2000);
// calling the client here
System.out.println("install the cxf client demo in root container");
// This test need to take sometime to download the cxf feature related bundles
System.out.println(executeCommand("features:install fabric-cxf", 600000, false));
String projectVersion = System.getProperty("fabricitest.version");
// install bundle of CXF demo client
System.out.println(executeCommand("osgi:install -s mvn:io.fabric8.examples/fabric-cxf-demo-common/" + projectVersion));
System.out.println(executeCommand("osgi:install -s mvn:io.fabric8.examples/fabric-cxf-demo-client/" + projectVersion));
System.out.println(executeCommand("osgi:list"));
System.out.println("invoking the web service");
Hello proxy = ServiceLocator.awaitService(bundleContext, Hello.class);
assertNotNull(proxy);
String result1 = proxy.sayHello();
String result2 = proxy.sayHello();
assertNotSame("We should get the two different result", result1, result2);
} finally {
ContainerBuilder.destroy(containers);
}
} finally {
fabricProxy.close();
}
}
Aggregations