use of org.apache.storm.daemon.worker.WorkerState in project storm by apache.
the class ExecutorTransferMultiThreadingTest method setup.
@Before
public void setup() throws NoSuchFieldException {
topoConf = Utils.readStormConfig();
String topologyId = "multi-threaded-topo-test";
StormTopology stormTopology = createStormTopology();
WorkerTopologyContext workerTopologyContext = mock(WorkerTopologyContext.class);
when(workerTopologyContext.getRawTopology()).thenReturn(stormTopology);
when(workerTopologyContext.getComponentId(selfTaskId)).thenReturn(sourceComp);
when(workerTopologyContext.getComponentId(remoteTaskId)).thenReturn(destComp);
workerState = mock(WorkerState.class);
when(workerState.getWorkerTopologyContext()).thenReturn(workerTopologyContext);
Map<Integer, JCQueue> receiveQMap = new HashMap<>();
// local recvQ is not important in this test; simple mock it
receiveQMap.put(selfTaskId, mock(JCQueue.class));
when(workerState.getLocalReceiveQueues()).thenReturn(receiveQMap);
when(workerState.getTopologyId()).thenReturn(topologyId);
when(workerState.getPort()).thenReturn(6701);
when(workerState.getMetricRegistry()).thenReturn(new StormMetricRegistry());
when(workerState.tryTransferRemote(any(), any(), any())).thenCallRealMethod();
// the actual worker transfer queue to be used in this test
// taskId for worker transfer queue should be -1.
// But there is already one worker transfer queue initialized by WorkerTransfer class (taskId=-1).
// However the taskId is only used for metrics and it is not important here. Making it -100 to avoid collision.
transferQueue = new JCQueue("worker-transfer-queue", "worker-transfer-queue", 1024, 0, 1, new WaitStrategyPark(100), workerState.getTopologyId(), Constants.SYSTEM_COMPONENT_ID, Collections.singletonList(-100), workerState.getPort(), workerState.getMetricRegistry());
// Replace the transferQueue inside WorkerTransfer (inside WorkerState) with the customized transferQueue to be used in this test
WorkerTransfer workerTransfer = new WorkerTransfer(workerState, topoConf, 2);
FieldSetter.setField(workerTransfer, workerTransfer.getClass().getDeclaredField("transferQueue"), transferQueue);
FieldSetter.setField(workerState, workerState.getClass().getDeclaredField("workerTransfer"), workerTransfer);
generalTopologyContext = mock(GeneralTopologyContext.class);
}
Aggregations