NMHeartBeatHandler extends BaseInterceptor { @VisibleForTesting protected boolean offerWithinResourceLimits(Resource currentResources, Resource offeredResources) { int newMemory = currentResources.getMemory() + offeredResources.getMemory(); int newCores = currentResources.getVirtualCores() + offeredResources.getVirtualCores(); return (newMemory <= conf.getJvmMaxMemoryMB() && newCores <= conf.getMaxCpus()); } @Inject  NMHeartBeatHandler(InterceptorRegistry registry, AbstractYarnScheduler yarnScheduler, MyriadDriver myriadDriver,
                            YarnNodeCapacityManager yarnNodeCapacityMgr, OfferLifecycleManager offerLifecycleMgr,
                            NodeStore nodeStore, SchedulerState state, NodeManagerConfiguration conf); @Override CallBackFilter getCallBackFilter(); @Override void beforeRMNodeEventHandled(RMNodeEvent event, RMContext context);  }
@Test public void testOfferWithinResourceLimits() throws Exception { Resource resourcesOne = Resource.newInstance(512, 1); Resource offerOne = Resource.newInstance(1024, 2); Resource offerTwo = Resource.newInstance(4096, 2); Resource offerThree = Resource.newInstance(1024, 8); assertTrue(handler.offerWithinResourceLimits(resourcesOne, offerOne)); assertFalse(handler.offerWithinResourceLimits(resourcesOne, offerTwo)); assertFalse(handler.offerWithinResourceLimits(resourcesOne, offerThree)); }