NECVEPlugin implements DevicePlugin, DevicePluginScheduler { @Override public Set<Device> allocateDevices(Set<Device> availableDevices, int count, Map<String, String> env) { Set<Device> allocated = new HashSet<>(); int number = 0; for (Device d : availableDevices) { allocated.add(d); number++; if (number == count) { break; } } return allocated; } NECVEPlugin(); @VisibleForTesting  NECVEPlugin(Function<String, String> envProvider, String[] scriptPaths,
      UdevUtil udev); @Override DeviceRegisterRequest getRegisterRequestInfo(); @Override Set<Device> getDevices(); @Override DeviceRuntimeSpec onDevicesAllocated(Set<Device> set,
      YarnRuntimeType yarnRuntimeType); @Override void onDevicesReleased(Set<Device> releasedDevices); @Override Set<Device> allocateDevices(Set<Device> availableDevices, int count,
      Map<String, String> env);  }
@Test public void testAllocateSingleDevice() throws ResourceHandlerException, IOException { setupTestDirectoryWithScript(); plugin = new NECVEPlugin(envProvider, defaultSearchDirs, udevUtil); Set<Device> available = new HashSet<>(); Device device = getTestDevice(0); available.add(device); Set<Device> allocated = plugin.allocateDevices(available, 1, env); assertEquals("No. of devices", 1, allocated.size()); Device allocatedDevice = allocated.iterator().next(); assertSame("Device", device, allocatedDevice); }
@Test public void testAllocateMultipleDevices() throws ResourceHandlerException, IOException { setupTestDirectoryWithScript(); plugin = new NECVEPlugin(envProvider, defaultSearchDirs, udevUtil); Set<Device> available = new HashSet<>(); Device device0 = getTestDevice(0); Device device1 = getTestDevice(1); available.add(device0); available.add(device1); Set<Device> allocated = plugin.allocateDevices(available, 2, env); assertEquals("No. of devices", 2, allocated.size()); assertTrue("Device missing", allocated.contains(device0)); assertTrue("Device missing", allocated.contains(device1)); }