Search in sources :

Example 1 with TestGlobalAddressModule

use of io.joynr.messaging.routing.TestGlobalAddressModule in project joynr by bmwcarit.

the class CcMessageRouterTest method setUp.

@Before
public void setUp() throws Exception {
    when(middlewareMessagingStubFactoryMock.create(any(ChannelAddress.class))).thenReturn(messagingStubMock);
    AbstractModule mockModule = new AbstractModule() {

        private Long msgRetryIntervalMs = 10L;

        // message runnables + cleanup thread
        private int numberOfThreads = maximumParallelSends + 1;

        private long routingTableGracePeriodMs = 30000;

        private long routingTableCleanupIntervalMs = 60000;

        @Override
        protected void configure() {
            bind(MessageRouter.class).to(CcMessageRouter.class);
            bind(RoutingTable.class).toInstance(routingTable);
            bind(AddressManager.class).toInstance(addressManager);
            bind(MulticastReceiverRegistry.class).toInstance(multicastReceiverRegistry);
            bind(ShutdownNotifier.class).toInstance(shutdownNotifier);
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_SEND_MSG_RETRY_INTERVAL_MS)).toInstance(msgRetryIntervalMs);
            bind(Integer.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_MESSAGING_MAXIMUM_PARALLEL_SENDS)).toInstance(maximumParallelSends);
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_ROUTING_TABLE_GRACE_PERIOD_MS)).toInstance(routingTableGracePeriodMs);
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_ROUTING_TABLE_CLEANUP_INTERVAL_MS)).toInstance(routingTableCleanupIntervalMs);
            bindConstant().annotatedWith(Names.named(ClusterControllerRuntimeModule.PROPERTY_ACCESSCONTROL_ENABLE)).to(false);
            bind(AccessController.class).toInstance(Mockito.mock(AccessController.class));
            bind(StatusReceiver.class).toInstance(statusReceiver);
            MapBinder<Class<? extends Address>, AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>> messagingStubFactory;
            messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
            }, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
            }, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
            messagingStubFactory.addBinding(ChannelAddress.class).toInstance(middlewareMessagingStubFactoryMock);
            MapBinder<Class<? extends Address>, IMessagingSkeleton> messagingSkeletonFactory;
            messagingSkeletonFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
            }, new TypeLiteral<IMessagingSkeleton>() {
            }, Names.named(MessagingSkeletonFactory.MIDDLEWARE_MESSAGING_SKELETONS));
            messagingSkeletonFactory.addBinding(ChannelAddress.class).toInstance(messagingSkeletonMock);
            Multibinder.newSetBinder(binder(), new TypeLiteral<MulticastAddressCalculator>() {
            });
        }

        @Provides
        @Named(MessageRouter.SCHEDULEDTHREADPOOL)
        ScheduledExecutorService provideMessageSchedulerThreadPoolExecutor() {
            ThreadFactory schedulerNamedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.MessageScheduler-scheduler-%d").build();
            ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(numberOfThreads, schedulerNamedThreadFactory);
            scheduler.setKeepAliveTime(100, TimeUnit.SECONDS);
            scheduler.allowCoreThreadTimeOut(true);
            return scheduler;
        }
    };
    testModule = Modules.override(mockModule).with(new TestGlobalAddressModule());
    Injector injector = Guice.createInjector(testModule);
    messageRouter = injector.getInstance(MessageRouter.class);
    ObjectMapper objectMapper = new ObjectMapper();
    messageFactory = new MutableMessageFactory(objectMapper, new HashSet<JoynrMessageProcessor>());
    // toParticipantId is globally visible
    final boolean isGloballyVisible = true;
    final long expiryDateMs = Long.MAX_VALUE;
    final boolean isSticky = true;
    final boolean allowUpdate = false;
    routingTable.put(toParticipantId, channelAddress, isGloballyVisible, expiryDateMs, isSticky, allowUpdate);
    Request request = new Request("noMethod", new Object[] {}, new String[] {}, "requestReplyId");
    joynrMessage = messageFactory.createRequest(fromParticipantId, toParticipantId, request, new MessagingQos());
    joynrMessage.setLocalMessage(true);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) IMessagingSkeleton(io.joynr.messaging.IMessagingSkeleton) Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) CcMessageRouter(io.joynr.messaging.routing.CcMessageRouter) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) StatusReceiver(io.joynr.statusmetrics.StatusReceiver) MessagingQos(io.joynr.messaging.MessagingQos) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ShutdownNotifier(io.joynr.runtime.ShutdownNotifier) Request(joynr.Request) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) AbstractModule(com.google.inject.AbstractModule) AbstractMiddlewareMessagingStubFactory(io.joynr.messaging.AbstractMiddlewareMessagingStubFactory) AccessController(io.joynr.accesscontrol.AccessController) MutableMessageFactory(io.joynr.dispatching.MutableMessageFactory) IMessagingStub(io.joynr.messaging.IMessagingStub) Before(org.junit.Before)

Example 2 with TestGlobalAddressModule

use of io.joynr.messaging.routing.TestGlobalAddressModule in project joynr by bmwcarit.

the class CapabilitiesDirectoryLauncher method start.

public static void start(Properties joynrConfig) {
    // LongPollingMessagingModule is only added in main(), since the servletMessagingModule will be used otherwise
    JoynrInjectorFactory injectorFactory = new JoynrInjectorFactory(joynrConfig, Modules.override(new JpaPersistModule("CapabilitiesDirectory"), new CCInProcessRuntimeModule()).with(new TestGlobalAddressModule(), new CapabilitiesDirectoryModule()));
    capabilitiesDirectoryLauncher = injectorFactory.createApplication(new JoynrApplicationModule("capabilitiesDirectoryLauncher", CapabilitiesDirectoryLauncher.class));
    capabilitiesDirectoryLauncher.run();
    capabilitiesDirectory = injectorFactory.getInjector().getInstance(CapabilitiesDirectoryImpl.class);
}
Also used : TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) JoynrApplicationModule(io.joynr.runtime.JoynrApplicationModule) JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory)

Example 3 with TestGlobalAddressModule

use of io.joynr.messaging.routing.TestGlobalAddressModule in project joynr by bmwcarit.

the class LocalDiscoveryTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    when(localDiscoveryEntryStoreMock.hasDiscoveryEntry(any(DiscoveryEntry.class))).thenReturn(true);
    // use default freshnessUpdateIntervalMs: 3600000ms (1h)
    final LocalCapabilitiesDirectoryImpl localCapabilitiesDirectory = new LocalCapabilitiesDirectoryImpl(capabilitiesProvisioningMock, globalAddressProviderMock, localDiscoveryEntryStoreMock, globalDiscoveryEntryCacheMock, messageRouterMock, globalCapabilitiesDirectoryClientMock, expiredDiscoveryEntryCacheCleanerMock, 3600000, capabilitiesFreshnessUpdateExecutorMock, defaultDiscoveryRetryIntervalMs, shutdownNotifier);
    Module testModule = Modules.override(new CCInProcessRuntimeModule()).with(new TestGlobalAddressModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(JoynrMessagingConnectorFactory.class).annotatedWith(Names.named("connectorFactoryMock")).toInstance(joynrMessagingConnectorFactoryMock);
            bind(LocalCapabilitiesDirectory.class).toInstance(localCapabilitiesDirectory);
            bind(LocalCapabilitiesDirectoryImpl.class).toInstance(localCapabilitiesDirectory);
            bind(ProxyInvocationHandlerFactory.class).to(ProxyInvocationHandlerFactoryImpl.class);
        }
    });
    Properties joynrProperties = new Properties();
    Injector injector = new JoynrInjectorFactory(new JoynrBaseModule(joynrProperties, testModule)).getInjector();
    runtime = injector.getInstance(JoynrRuntime.class);
}
Also used : TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) LocalCapabilitiesDirectoryImpl(io.joynr.capabilities.LocalCapabilitiesDirectoryImpl) JoynrBaseModule(io.joynr.runtime.JoynrBaseModule) Properties(java.util.Properties) AbstractModule(com.google.inject.AbstractModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory) JoynrRuntime(io.joynr.runtime.JoynrRuntime) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) JoynrMessagingConnectorFactory(io.joynr.proxy.JoynrMessagingConnectorFactory) Injector(com.google.inject.Injector) Module(com.google.inject.Module) JoynrBaseModule(io.joynr.runtime.JoynrBaseModule) TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 4 with TestGlobalAddressModule

use of io.joynr.messaging.routing.TestGlobalAddressModule in project joynr by bmwcarit.

the class ProxyErrorsTest method getRuntime.

protected JoynrRuntime getRuntime(Properties joynrConfig, Module... modules) {
    Module runtimeModule = new CCInProcessRuntimeModule();
    Module modulesWithRuntime = Modules.override(runtimeModule).with(modules);
    modulesWithRuntime = Modules.override(modulesWithRuntime).with(new TestGlobalAddressModule());
    DummyJoynrApplication application = (DummyJoynrApplication) new JoynrInjectorFactory(joynrConfig, modulesWithRuntime).createApplication(DummyJoynrApplication.class);
    return application.getRuntime();
}
Also used : TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) DummyJoynrApplication(io.joynr.integration.util.DummyJoynrApplication) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) Module(com.google.inject.Module) TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory)

Example 5 with TestGlobalAddressModule

use of io.joynr.messaging.routing.TestGlobalAddressModule in project joynr by bmwcarit.

the class ShortCircuitTest method setup.

@Before
public void setup() throws Exception {
    Module runtimeModule = Modules.override(new CCInProcessRuntimeModule()).with(new TestGlobalAddressModule());
    Properties joynrConfig = new Properties();
    DummyJoynrApplication application = (DummyJoynrApplication) new JoynrInjectorFactory(joynrConfig, runtimeModule).createApplication(DummyJoynrApplication.class);
    runtime = application.getRuntime();
    DiscoveryQos discoveryQos = new DiscoveryQos(CONST_DEFAULT_TEST_TIMEOUT, ArbitrationStrategy.HighestPriority, DiscoveryQos.NO_MAX_AGE, DiscoveryScope.LOCAL_ONLY);
    ProxyBuilder<EchoProxy> proxyBuilder = runtime.getProxyBuilder(DOMAIN, EchoProxy.class).setDiscoveryQos(discoveryQos);
    echoProxy = proxyBuilder.build();
    EchoProvider echoProvider = new EchoProviderImpl();
    ProviderQos providerQos = new ProviderQos();
    providerQos.setPriority(System.currentTimeMillis());
    providerQos.setScope(ProviderScope.LOCAL);
    runtime.registerProvider(DOMAIN, echoProvider, providerQos);
    // warmup
    for (int i = 0; i < 100; i++) {
        echoProxy.echoString("warmup");
        echoProxy.echoByteArray(new Byte[1]);
    }
}
Also used : TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) DummyJoynrApplication(io.joynr.integration.util.DummyJoynrApplication) EchoProvider(joynr.tests.performance.EchoProvider) Properties(java.util.Properties) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrInjectorFactory(io.joynr.runtime.JoynrInjectorFactory) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) Module(com.google.inject.Module) TestGlobalAddressModule(io.joynr.messaging.routing.TestGlobalAddressModule) CCInProcessRuntimeModule(io.joynr.runtime.CCInProcessRuntimeModule) AbstractModule(com.google.inject.AbstractModule) EchoProxy(joynr.tests.performance.EchoProxy) ProviderQos(joynr.types.ProviderQos) Before(org.junit.Before)

Aggregations

TestGlobalAddressModule (io.joynr.messaging.routing.TestGlobalAddressModule)6 CCInProcessRuntimeModule (io.joynr.runtime.CCInProcessRuntimeModule)5 JoynrInjectorFactory (io.joynr.runtime.JoynrInjectorFactory)5 Module (com.google.inject.Module)4 Before (org.junit.Before)4 AbstractModule (com.google.inject.AbstractModule)3 Properties (java.util.Properties)3 Injector (com.google.inject.Injector)2 DummyJoynrApplication (io.joynr.integration.util.DummyJoynrApplication)2 ProviderQos (joynr.types.ProviderQos)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 TypeLiteral (com.google.inject.TypeLiteral)1 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)1 AccessController (io.joynr.accesscontrol.AccessController)1 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)1 LocalCapabilitiesDirectoryImpl (io.joynr.capabilities.LocalCapabilitiesDirectoryImpl)1 MutableMessageFactory (io.joynr.dispatching.MutableMessageFactory)1 AbstractMiddlewareMessagingStubFactory (io.joynr.messaging.AbstractMiddlewareMessagingStubFactory)1 IMessagingSkeleton (io.joynr.messaging.IMessagingSkeleton)1