Java Code Examples for org.apache.reef.tang.Injector#bindVolatileParameter()
The following examples show how to use
org.apache.reef.tang.Injector#bindVolatileParameter() .
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: DriverRPCServer.java From incubator-nemo with Apache License 2.0 | 6 votes |
/** * Runs the RPC server. * Specifically, creates a {@link NettyMessagingTransport} and binds it to a listening port. */ public void run() { // Calling 'run' multiple times is considered invalid, since it will override state variables like // 'transport', and 'host'. ensureServerState(false); try { final Injector injector = Tang.Factory.getTang().newInjector(); final LocalAddressProvider localAddressProvider = injector.getInstance(LocalAddressProvider.class); host = localAddressProvider.getLocalAddress(); injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, host); injector.bindVolatileParameter(RemoteConfiguration.Port.class, 0); injector.bindVolatileParameter(RemoteConfiguration.RemoteServerStage.class, new SyncStage<>(new ServerEventHandler())); transport = injector.getInstance(NettyMessagingTransport.class); LOG.info("DriverRPCServer running at {}", transport.getListeningPort()); isRunning = true; } catch (final InjectionException e) { throw new RuntimeException(e); } }
Example 2
Source File: NameRegistryClient.java From reef with Apache License 2.0 | 6 votes |
/** * Constructs a naming registry client. * * @param serverAddr a name server address * @param serverPort a name server port * @param timeout timeout in ms * @param factory an identifier factory */ NameRegistryClient(final String serverAddr, final int serverPort, final long timeout, final IdentifierFactory factory, final LocalAddressProvider localAddressProvider) { this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort); this.timeout = timeout; this.codec = NamingCodecFactory.createRegistryCodec(factory); this.replyQueue = new LinkedBlockingQueue<>(); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, localAddressProvider.getLocalAddress()); injector.bindVolatileParameter(RemoteConfiguration.RemoteClientStage.class, new SyncStage<>(new NamingRegistryClientHandler(new NamingRegistryResponseHandler(replyQueue), codec))); try { this.transport = injector.getInstance(NettyMessagingTransport.class); } catch (final InjectionException e) { throw new RuntimeException(e); } }
Example 3
Source File: MessagingTransportFactory.java From reef with Apache License 2.0 | 6 votes |
/** * Creates a transport. * * @param port a listening port * @param clientHandler a transport client side handler * @param serverHandler a transport server side handler * @param exHandler a exception handler */ @Override public Transport newInstance(final int port, final EventHandler<TransportEvent> clientHandler, final EventHandler<TransportEvent> serverHandler, final EventHandler<Exception> exHandler) { final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, this.localAddress); injector.bindVolatileParameter(RemoteConfiguration.Port.class, port); injector.bindVolatileParameter(RemoteConfiguration.RemoteClientStage.class, new SyncStage<>(clientHandler)); injector.bindVolatileParameter(RemoteConfiguration.RemoteServerStage.class, new SyncStage<>(serverHandler)); final Transport transport; try { transport = injector.getInstance(NettyMessagingTransport.class); transport.registerErrorHandler(exHandler); return transport; } catch (final InjectionException e) { throw new RuntimeException(e); } }
Example 4
Source File: RunningJobsImpl.java From reef with Apache License 2.0 | 5 votes |
/** * @param jobIdentifier * @param remoteIdentifier * @return * @throws BindException * @throws InjectionException */ private synchronized RunningJobImpl newRunningJob(final String jobIdentifier, final String remoteIdentifier) throws BindException, InjectionException { final Injector child = this.injector.forkInjector(); child.bindVolatileParameter(REEFImplementation.DriverRemoteIdentifier.class, remoteIdentifier); child.bindVolatileParameter(DriverIdentifier.class, jobIdentifier); return child.getInstance(RunningJobImpl.class); }
Example 5
Source File: NameClientTest.java From reef with Apache License 2.0 | 5 votes |
/** * Test method for {@link org.apache.reef.io.network.naming.NameClient#close()}. * * @throws Exception */ @Test public final void testClose() throws Exception { final String localAddress = localAddressProvider.getLocalAddress(); final IdentifierFactory factory = new StringIdentifierFactory(); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(NameServerParameters.NameServerIdentifierFactory.class, factory); injector.bindVolatileInstance(LocalAddressProvider.class, this.localAddressProvider); try (NameServer server = injector.getInstance(NameServer.class)) { final int serverPort = server.getPort(); final Configuration nameResolverConf = NameResolverConfiguration.CONF .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, localAddress) .set(NameResolverConfiguration.NAME_SERVICE_PORT, serverPort) .set(NameResolverConfiguration.CACHE_TIMEOUT, 10000) .set(NameResolverConfiguration.RETRY_TIMEOUT, RETRY_TIMEOUT) .set(NameResolverConfiguration.RETRY_COUNT, RETRY_COUNT) .build(); try (NameResolver client = Tang.Factory.getTang().newInjector(nameResolverConf).getInstance(NameClient.class)) { final Identifier id = factory.getNewInstance("Task1"); client.register(id, new InetSocketAddress(localAddress, 7001)); client.unregister(id); Thread.sleep(100); } } }
Example 6
Source File: BlockStoreTest.java From incubator-nemo with Apache License 2.0 | 5 votes |
/** * Test {@link MemoryStore}. * * @throws Exception exception on the way. */ @Test(timeout = 10000) public void testMemoryStore() throws Exception { final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileInstance(SerializerManager.class, serializerManager); injector.bindVolatileParameter(JobConf.ExecutorMemoryMb.class, 640); injector.bindVolatileParameter(JobConf.MaxOffheapRatio.class, 0.2); final BlockStore memoryStore = injector.getInstance(MemoryStore.class); shuffle(memoryStore, memoryStore); concurrentRead(memoryStore, memoryStore); shuffleInHashRange(memoryStore, memoryStore); }
Example 7
Source File: CommunicationGroupDriverImpl.java From reef with Apache License 2.0 | 5 votes |
/** * @deprecated in 0.14. Use Tang to obtain an instance of this instead. */ @Deprecated public CommunicationGroupDriverImpl(final Class<? extends Name<String>> groupName, final ConfigurationSerializer confSerializer, final EStage<GroupCommunicationMessage> senderStage, final BroadcastingEventHandler<RunningTask> groupCommRunningTaskHandler, final BroadcastingEventHandler<FailedTask> groupCommFailedTaskHandler, final BroadcastingEventHandler<FailedEvaluator> groupCommFailedEvaluatorHandler, final BroadcastingEventHandler<GroupCommunicationMessage> commGroupMessageHandler, final String driverId, final int numberOfTasks, final int fanOut) { super(); this.groupName = groupName; this.driverId = driverId; this.confSerializer = confSerializer; this.allInitialTasksRunning = new CountingSemaphore(numberOfTasks, getQualifiedName(), topologiesLock); groupCommRunningTaskHandler.addHandler(new TopologyRunningTaskHandler(this)); groupCommFailedTaskHandler.addHandler(new TopologyFailedTaskHandler(this)); groupCommFailedEvaluatorHandler.addHandler(new TopologyFailedEvaluatorHandler(this)); commGroupMessageHandler.addHandler(new TopologyMessageHandler(this)); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(CommGroupNameClass.class, groupName); injector.bindVolatileParameter(GroupCommSenderStage.class, senderStage); injector.bindVolatileParameter(DriverIdentifier.class, driverId); injector.bindVolatileParameter(CommGroupNumTask.class, numberOfTasks); injector.bindVolatileParameter(TreeTopologyFanOut.class, fanOut); try { topologyFactory = injector.getInstance(TopologyFactory.class); } catch (final InjectionException e) { throw new RuntimeException(e); } this.topologyClass = TreeTopology.class; }
Example 8
Source File: BlockStoreTest.java From incubator-nemo with Apache License 2.0 | 5 votes |
private GlusterFileStore createGlusterFileStore(final String executorId) throws InjectionException { final Injector injector = LocalMessageEnvironment.forkInjector(baseInjector, executorId); injector.bindVolatileParameter(JobConf.GlusterVolumeDirectory.class, TMP_FILE_DIRECTORY); injector.bindVolatileParameter(JobConf.JobId.class, "GFS test"); injector.bindVolatileParameter(JobConf.ExecutorId.class, executorId); injector.bindVolatileInstance(SerializerManager.class, serializerManager); injector.bindVolatileParameter(JobConf.ExecutorMemoryMb.class, 640); injector.bindVolatileParameter(JobConf.MaxOffheapRatio.class, 0.2); return injector.getInstance(GlusterFileStore.class); }
Example 9
Source File: CommunicationGroupDriverFactory.java From reef with Apache License 2.0 | 5 votes |
/** * Instantiates a new CommunicationGroupDriver instance. * @param groupName specified name of the communication group * @param topologyClass topology implementation * @param numberOfTasks minimum number of tasks needed in this group before start * @param customFanOut fanOut for TreeTopology * @return CommunicationGroupDriver instance * @throws InjectionException */ public CommunicationGroupDriver getNewInstance( final Class<? extends Name<String>> groupName, final Class<? extends Topology> topologyClass, final int numberOfTasks, final int customFanOut) throws InjectionException { final Injector newInjector = injector.forkInjector(); newInjector.bindVolatileParameter(CommGroupNameClass.class, groupName); newInjector.bindVolatileParameter(TopologyClass.class, topologyClass); newInjector.bindVolatileParameter(CommGroupNumTask.class, numberOfTasks); newInjector.bindVolatileParameter(TreeTopologyFanOut.class, customFanOut); return newInjector.getInstance(CommunicationGroupDriver.class); }
Example 10
Source File: NemoBackendTest.java From incubator-nemo with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { this.dag = new IRDAG(builder.addVertex(source).addVertex(map1).addVertex(groupByKey).addVertex(combine).addVertex(map2) .connectVertices(new IREdge(CommunicationPatternProperty.Value.ONE_TO_ONE, source, map1)) .connectVertices(EmptyComponents.newDummyShuffleEdge(map1, groupByKey)) .connectVertices(new IREdge(CommunicationPatternProperty.Value.ONE_TO_ONE, groupByKey, combine)) .connectVertices(new IREdge(CommunicationPatternProperty.Value.ONE_TO_ONE, combine, map2)) .build()); this.dag = new TransientResourcePolicy().runCompileTimeOptimization(dag, EMPTY_DAG_DIRECTORY); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(JobConf.DAGDirectory.class, ""); this.nemoBackend = injector.getInstance(NemoBackend.class); }
Example 11
Source File: ClientEndpointTest.java From nemo with Apache License 2.0 | 5 votes |
@Test(timeout = 3000) public void testState() throws Exception { // Create a simple client endpoint that returns given job state. final StateTranslator stateTranslator = mock(StateTranslator.class); when(stateTranslator.translateState(any())).then(state -> state.getArgument(0)); final ClientEndpoint clientEndpoint = new TestClientEndpoint(stateTranslator); assertEquals(clientEndpoint.getJobState(), JobState.State.READY); // Wait for connection but not connected. assertEquals(clientEndpoint.waitUntilJobFinish(100, TimeUnit.MILLISECONDS), JobState.State.READY); // Create a JobStateManager of an empty dag and create a DriverEndpoint with it. final DAGBuilder<IRVertex, IREdge> irDagBuilder = new DAGBuilder<>(); final DAG<IRVertex, IREdge> irDAG = irDagBuilder.build(); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(JobConf.DAGDirectory.class, ""); final PhysicalPlanGenerator physicalPlanGenerator = injector.getInstance(PhysicalPlanGenerator.class); final DAG<PhysicalStage, PhysicalStageEdge> physicalDAG = irDAG.convert(physicalPlanGenerator); final LocalMessageDispatcher messageDispatcher = new LocalMessageDispatcher(); final LocalMessageEnvironment messageEnvironment = new LocalMessageEnvironment(MessageEnvironment.MASTER_COMMUNICATION_ID, messageDispatcher); injector.bindVolatileInstance(MessageEnvironment.class, messageEnvironment); final BlockManagerMaster pmm = injector.getInstance(BlockManagerMaster.class); final JobStateManager jobStateManager = new JobStateManager( new PhysicalPlan("TestPlan", physicalDAG, physicalPlanGenerator.getTaskIRVertexMap()), pmm, metricMessageHandler, MAX_SCHEDULE_ATTEMPT); final DriverEndpoint driverEndpoint = new DriverEndpoint(jobStateManager, clientEndpoint); // Check the current state. assertEquals(clientEndpoint.getJobState(), JobState.State.EXECUTING); // Wait for the job to finish but not finished assertEquals(clientEndpoint.waitUntilJobFinish(100, TimeUnit.MILLISECONDS), JobState.State.EXECUTING); // Check finish. jobStateManager.onJobStateChanged(JobState.State.COMPLETE); assertEquals(clientEndpoint.waitUntilJobFinish(), JobState.State.COMPLETE); }
Example 12
Source File: JobStateManagerTest.java From nemo with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { irDAGBuilder = new DAGBuilder<>(); final LocalMessageDispatcher messageDispatcher = new LocalMessageDispatcher(); final LocalMessageEnvironment messageEnvironment = new LocalMessageEnvironment(MessageEnvironment.MASTER_COMMUNICATION_ID, messageDispatcher); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileInstance(MessageEnvironment.class, messageEnvironment); blockManagerMaster = injector.getInstance(BlockManagerMaster.class); metricMessageHandler = mock(MetricMessageHandler.class); injector.bindVolatileParameter(JobConf.DAGDirectory.class, ""); physicalPlanGenerator = injector.getInstance(PhysicalPlanGenerator.class); }
Example 13
Source File: FaultToleranceTest.java From nemo with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { RuntimeTestUtil.initialize(); irDAGBuilder = new DAGBuilder<>(); metricMessageHandler = mock(MetricMessageHandler.class); pubSubEventHandler = mock(PubSubEventHandlerWrapper.class); updatePhysicalPlanEventHandler = mock(UpdatePhysicalPlanEventHandler.class); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(JobConf.DAGDirectory.class, ""); physicalPlanGenerator = injector.getInstance(PhysicalPlanGenerator.class); }
Example 14
Source File: SingleTaskGroupQueueTest.java From nemo with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception{ irDAGBuilder = new DAGBuilder<>(); pendingTaskGroupPriorityQueue = new SingleJobTaskGroupQueue(); executorService = Executors.newFixedThreadPool(2); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(JobConf.DAGDirectory.class, ""); physicalPlanGenerator = injector.getInstance(PhysicalPlanGenerator.class); }
Example 15
Source File: NetworkServiceTest.java From reef with Apache License 2.0 | 4 votes |
/** * NetworkService messaging rate benchmark. */ @Test public void testMessagingNetworkServiceBatchingRate() throws Exception { Assume.assumeFalse("Use log level INFO to run benchmarking", LOG.isLoggable(Level.FINEST)); LOG.log(Level.FINEST, name.getMethodName()); final IdentifierFactory factory = new StringIdentifierFactory(); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(NameServerParameters.NameServerIdentifierFactory.class, factory); injector.bindVolatileInstance(LocalAddressProvider.class, this.localAddressProvider); try (NameServer server = injector.getInstance(NameServer.class)) { final int nameServerPort = server.getPort(); final int batchSize = 1024 * 1024; final int[] messageSizes = {32, 64, 512}; for (final int size : messageSizes) { final int numMessages = 300 / (Math.max(1, size / 512)); final Monitor monitor = new Monitor(); // network service final String name2 = "task2"; final String name1 = "task1"; final Configuration nameResolverConf = Tang.Factory.getTang().newConfigurationBuilder(NameResolverConfiguration.CONF .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, this.localAddress) .set(NameResolverConfiguration.NAME_SERVICE_PORT, nameServerPort) .build()) .build(); final Injector injector2 = Tang.Factory.getTang().newInjector(nameResolverConf); LOG.log(Level.FINEST, "=== Test network service receiver start"); LOG.log(Level.FINEST, "=== Test network service sender start"); try (NameResolver nameResolver = injector2.getInstance(NameResolver.class)) { injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class, factory); injector2.bindVolatileInstance(NameResolver.class, nameResolver); injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceCodec.class, new StringCodec()); injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceTransportFactory.class, injector.getInstance(MessagingTransportFactory.class)); injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceExceptionHandler.class, new ExceptionHandler()); final Injector injectorNs2 = injector2.forkInjector(); injectorNs2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class, new MessageHandler<String>(name2, monitor, numMessages)); final NetworkService<String> ns2 = injectorNs2.getInstance(NetworkService.class); final Injector injectorNs1 = injector2.forkInjector(); injectorNs1.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class, new MessageHandler<String>(name1, null, 0)); final NetworkService<String> ns1 = injectorNs1.getInstance(NetworkService.class); ns2.registerId(factory.getNewInstance(name2)); final int port2 = ns2.getTransport().getListeningPort(); server.register(factory.getNewInstance("task2"), new InetSocketAddress(this.localAddress, port2)); ns1.registerId(factory.getNewInstance(name1)); final int port1 = ns1.getTransport().getListeningPort(); server.register(factory.getNewInstance("task1"), new InetSocketAddress(this.localAddress, port1)); final Identifier destId = factory.getNewInstance(name2); final String message = StringUtils.repeat('1', batchSize); final long start = System.currentTimeMillis(); try (Connection<String> conn = ns1.newConnection(destId)) { conn.open(); for (int i = 0; i < numMessages; i++) { conn.write(message); } monitor.mwait(); } catch (final NetworkException e) { e.printStackTrace(); throw new RuntimeException(e); } final long end = System.currentTimeMillis(); final double runtime = ((double) end - start) / 1000; final long numAppMessages = numMessages * batchSize / size; LOG.log(Level.FINEST, "size: " + size + "; messages/s: " + numAppMessages / runtime + " bandwidth(bytes/s): " + ((double) numAppMessages * 2 * size) / runtime); // x2 for unicode chars } } } }
Example 16
Source File: NetworkServiceTest.java From reef with Apache License 2.0 | 4 votes |
/** * NetworkService messaging rate benchmark. */ @Test public void testMessagingNetworkServiceRate() throws Exception { Assume.assumeFalse("Use log level INFO to run benchmarking", LOG.isLoggable(Level.FINEST)); LOG.log(Level.FINEST, name.getMethodName()); final IdentifierFactory factory = new StringIdentifierFactory(); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(NameServerParameters.NameServerIdentifierFactory.class, factory); injector.bindVolatileInstance(LocalAddressProvider.class, this.localAddressProvider); try (NameServer server = injector.getInstance(NameServer.class)) { final int nameServerPort = server.getPort(); final int[] messageSizes = {1, 16, 32, 64, 512, 64 * 1024, 1024 * 1024}; for (final int size : messageSizes) { final int numMessages = 300000 / (Math.max(1, size / 512)); final Monitor monitor = new Monitor(); // network service final String name2 = "task2"; final String name1 = "task1"; final Configuration nameResolverConf = Tang.Factory.getTang().newConfigurationBuilder(NameResolverConfiguration.CONF .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, this.localAddress) .set(NameResolverConfiguration.NAME_SERVICE_PORT, nameServerPort) .build()) .build(); final Injector injector2 = Tang.Factory.getTang().newInjector(nameResolverConf); LOG.log(Level.FINEST, "=== Test network service receiver start"); LOG.log(Level.FINEST, "=== Test network service sender start"); try (NameResolver nameResolver = injector2.getInstance(NameResolver.class)) { injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class, factory); injector2.bindVolatileInstance(NameResolver.class, nameResolver); injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceCodec.class, new StringCodec()); injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceTransportFactory.class, injector.getInstance(MessagingTransportFactory.class)); injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceExceptionHandler.class, new ExceptionHandler()); final Injector injectorNs2 = injector2.forkInjector(); injectorNs2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class, new MessageHandler<String>(name2, monitor, numMessages)); final NetworkService<String> ns2 = injectorNs2.getInstance(NetworkService.class); final Injector injectorNs1 = injector2.forkInjector(); injectorNs1.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class, new MessageHandler<String>(name1, null, 0)); final NetworkService<String> ns1 = injectorNs1.getInstance(NetworkService.class); ns2.registerId(factory.getNewInstance(name2)); final int port2 = ns2.getTransport().getListeningPort(); server.register(factory.getNewInstance("task2"), new InetSocketAddress(this.localAddress, port2)); ns1.registerId(factory.getNewInstance(name1)); final int port1 = ns1.getTransport().getListeningPort(); server.register(factory.getNewInstance("task1"), new InetSocketAddress(this.localAddress, port1)); final Identifier destId = factory.getNewInstance(name2); final String message = StringUtils.repeat('1', size); final long start = System.currentTimeMillis(); try (Connection<String> conn = ns1.newConnection(destId)) { conn.open(); for (int i = 0; i < numMessages; i++) { conn.write(message); } monitor.mwait(); } catch (final NetworkException e) { e.printStackTrace(); throw new RuntimeException(e); } final long end = System.currentTimeMillis(); final double runtime = ((double) end - start) / 1000; LOG.log(Level.FINEST, "size: " + size + "; messages/s: " + numMessages / runtime + " bandwidth(bytes/s): " + ((double) numMessages * 2 * size) / runtime); // x2 for unicode chars } } } }
Example 17
Source File: DataTransferTest.java From incubator-nemo with Apache License 2.0 | 4 votes |
@Before public void setUp() throws InjectionException { final Configuration configuration = Tang.Factory.getTang().newConfigurationBuilder() .bindNamedParameter(JobConf.ScheduleSerThread.class, "1") .build(); final Injector baseInjector = Tang.Factory.getTang().newInjector(configuration); baseInjector.bindVolatileInstance(EvaluatorRequestor.class, mock(EvaluatorRequestor.class)); final Injector dispatcherInjector = LocalMessageDispatcher.forkInjector(baseInjector); final Injector injector = LocalMessageEnvironment.forkInjector(dispatcherInjector, MessageEnvironment.MASTER_COMMUNICATION_ID); final PlanRewriter planRewriter = mock(PlanRewriter.class); injector.bindVolatileInstance(PlanRewriter.class, planRewriter); injector.bindVolatileInstance(PubSubEventHandlerWrapper.class, mock(PubSubEventHandlerWrapper.class)); final AtomicInteger executorCount = new AtomicInteger(0); injector.bindVolatileInstance(ClientRPC.class, mock(ClientRPC.class)); injector.bindVolatileInstance(MetricManagerMaster.class, mock(MetricManagerMaster.class)); injector.bindVolatileInstance(MetricMessageHandler.class, mock(MetricMessageHandler.class)); injector.bindVolatileParameter(JobConf.DAGDirectory.class, EMPTY_DAG_DIRECTORY); injector.bindVolatileParameter(JobConf.JobId.class, "jobId"); // Necessary for wiring up the message environments injector.bindVolatileInstance(Scheduler.class, injector.getInstance(BatchScheduler.class)); injector.getInstance(RuntimeMaster.class); final BlockManagerMaster master = injector.getInstance(BlockManagerMaster.class); final MetricManagerWorker metricMessageSender = injector.getInstance(MetricManagerWorker.class); final Injector nameClientInjector = createNameClientInjector(); nameClientInjector.bindVolatileParameter(JobConf.JobId.class, "data transfer test"); this.master = master; final Pair<BlockManagerWorker, IntermediateDataIOFactory> pair1 = createWorker( EXECUTOR_ID_PREFIX + executorCount.getAndIncrement(), dispatcherInjector, nameClientInjector); this.worker1 = pair1.left(); this.transferFactory = pair1.right(); this.worker2 = createWorker(EXECUTOR_ID_PREFIX + executorCount.getAndIncrement(), dispatcherInjector, nameClientInjector).left(); this.metricMessageSender = metricMessageSender; }
Example 18
Source File: NetworkServiceTest.java From reef with Apache License 2.0 | 4 votes |
/** * NetworkService messaging test. */ @Test public void testMessagingNetworkService() throws Exception { LOG.log(Level.FINEST, name.getMethodName()); final IdentifierFactory factory = new StringIdentifierFactory(); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(NameServerParameters.NameServerIdentifierFactory.class, factory); injector.bindVolatileInstance(LocalAddressProvider.class, this.localAddressProvider); try (NameServer server = injector.getInstance(NameServer.class)) { final int nameServerPort = server.getPort(); final int numMessages = 10; final Monitor monitor = new Monitor(); // network service final String name2 = "task2"; final String name1 = "task1"; final Configuration nameResolverConf = Tang.Factory.getTang().newConfigurationBuilder(NameResolverConfiguration.CONF .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, this.localAddress) .set(NameResolverConfiguration.NAME_SERVICE_PORT, nameServerPort) .build()) .build(); final Injector injector2 = Tang.Factory.getTang().newInjector(nameResolverConf); LOG.log(Level.FINEST, "=== Test network service receiver start"); LOG.log(Level.FINEST, "=== Test network service sender start"); try (NameResolver nameResolver = injector2.getInstance(NameResolver.class)) { injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class, factory); injector2.bindVolatileInstance(NameResolver.class, nameResolver); injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceCodec.class, new StringCodec()); injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceTransportFactory.class, injector.getInstance(MessagingTransportFactory.class)); injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceExceptionHandler.class, new ExceptionHandler()); final Injector injectorNs2 = injector2.forkInjector(); injectorNs2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class, new MessageHandler<String>(name2, monitor, numMessages)); final NetworkService<String> ns2 = injectorNs2.getInstance(NetworkService.class); final Injector injectorNs1 = injector2.forkInjector(); injectorNs1.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class, new MessageHandler<String>(name1, null, 0)); final NetworkService<String> ns1 = injectorNs1.getInstance(NetworkService.class); ns2.registerId(factory.getNewInstance(name2)); final int port2 = ns2.getTransport().getListeningPort(); server.register(factory.getNewInstance("task2"), new InetSocketAddress(this.localAddress, port2)); ns1.registerId(factory.getNewInstance(name1)); final int port1 = ns1.getTransport().getListeningPort(); server.register(factory.getNewInstance("task1"), new InetSocketAddress(this.localAddress, port1)); final Identifier destId = factory.getNewInstance(name2); try (Connection<String> conn = ns1.newConnection(destId)) { conn.open(); for (int count = 0; count < numMessages; ++count) { conn.write("hello! " + count); } monitor.mwait(); } catch (final NetworkException e) { e.printStackTrace(); throw new RuntimeException(e); } } } }
Example 19
Source File: NameClientTest.java From reef with Apache License 2.0 | 4 votes |
/** * Test method for {@link org.apache.reef.io.network.naming.NameClient#lookup()}. * To check caching behavior with expireAfterAccess & expireAfterWrite * Changing NameCache's pattern to expireAfterAccess causes this test to fail * * @throws Exception */ @Test public final void testLookup() throws Exception { final String localAddress = localAddressProvider.getLocalAddress(); final IdentifierFactory factory = new StringIdentifierFactory(); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(NameServerParameters.NameServerIdentifierFactory.class, factory); injector.bindVolatileInstance(LocalAddressProvider.class, this.localAddressProvider); try (NameServer server = injector.getInstance(NameServer.class)) { final int serverPort = server.getPort(); final Configuration nameResolverConf = NameResolverConfiguration.CONF .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, localAddress) .set(NameResolverConfiguration.NAME_SERVICE_PORT, serverPort) .set(NameResolverConfiguration.CACHE_TIMEOUT, 150) .set(NameResolverConfiguration.RETRY_TIMEOUT, RETRY_TIMEOUT) .set(NameResolverConfiguration.RETRY_COUNT, RETRY_COUNT) .build(); try (NameResolver client = Tang.Factory.getTang().newInjector(nameResolverConf).getInstance(NameClient.class)) { final Identifier id = factory.getNewInstance("Task1"); client.register(id, new InetSocketAddress(localAddress, 7001)); client.lookup(id); // caches the entry client.unregister(id); Thread.sleep(100); try { InetSocketAddress addr = client.lookup(id); Thread.sleep(100); //With expireAfterAccess, the previous lookup would reset expiry to 150ms //more and 100ms wait will not expire the item and will return the cached value //With expireAfterWrite, the extra wait of 100 ms will expire the item //resulting in NamingException and the test passes addr = client.lookup(id); Assert.assertNull("client.lookup(id)", addr); } catch (final Exception e) { if (e instanceof ExecutionException) { Assert.assertTrue("Execution Exception cause is instanceof NamingException", e.getCause() instanceof NamingException); } else { throw e; } } } } }
Example 20
Source File: RuntimesHost.java From reef with Apache License 2.0 | 2 votes |
/** * Copy event handler from current class configuration into runtime injector. * This is a helper method called from initializeInjector() only. * @param runtimeInjector Runtime injector to copy event handler to. * @param param Class that identifies the event handler parameter. * @param <T> Type of the event handler. * @throws InjectionException If configuration error occurs. */ private <T extends EventHandler<?>> void copyEventHandler( final Injector runtimeInjector, final Class<? extends Name<T>> param) throws InjectionException { runtimeInjector.bindVolatileParameter(param, this.originalInjector.getNamedInstance(param)); }