@Test public void testMergeWithSerializationCopy() throws Exception { final ResourceSpec spec1 = CommonTestUtils.createCopySerializable(ResourceSpec.UNKNOWN); final ResourceSpec spec2 = CommonTestUtils.createCopySerializable(ResourceSpec.UNKNOWN); final ResourceSpec merged = spec1.merge(spec2); assertEquals(ResourceSpec.UNKNOWN, merged); }
public ResourceSpec merge(ResourceSpec other) { if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } ResourceSpec target = new ResourceSpec( Math.max(this.cpuCores, other.cpuCores), this.heapMemoryInMB + other.heapMemoryInMB, this.directMemoryInMB + other.directMemoryInMB, this.nativeMemoryInMB + other.nativeMemoryInMB, this.stateSizeInMB + other.stateSizeInMB, this.managedMemoryInMB + other.managedMemoryInMB); target.extendedResources.putAll(extendedResources); for (Resource resource : other.extendedResources.values()) { target.extendedResources.merge(resource.getName(), resource, (v1, v2) -> v1.merge(v2)); } return target; }
ResourceSpec implements Serializable { public ResourceSpec merge(ResourceSpec other) { if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } ResourceSpec target = new ResourceSpec( Math.max(this.cpuCores, other.cpuCores), this.heapMemoryInMB + other.heapMemoryInMB, this.directMemoryInMB + other.directMemoryInMB, this.nativeMemoryInMB + other.nativeMemoryInMB, this.stateSizeInMB + other.stateSizeInMB, this.managedMemoryInMB + other.managedMemoryInMB); target.extendedResources.putAll(extendedResources); for (Resource resource : other.extendedResources.values()) { target.extendedResources.merge(resource.getName(), resource, (v1, v2) -> v1.merge(v2)); } return target; } }
ResourceSpec implements Serializable { public ResourceSpec merge(ResourceSpec other) { if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } ResourceSpec target = new ResourceSpec( Math.max(this.cpuCores, other.cpuCores), this.heapMemoryInMB + other.heapMemoryInMB, this.directMemoryInMB + other.directMemoryInMB, this.nativeMemoryInMB + other.nativeMemoryInMB, this.stateSizeInMB + other.stateSizeInMB, this.managedMemoryInMB + other.managedMemoryInMB); target.extendedResources.putAll(extendedResources); for (Resource resource : other.extendedResources.values()) { target.extendedResources.merge(resource.getName(), resource, (v1, v2) -> v1.merge(v2)); } return target; } private  ResourceSpec(
			double cpuCores,
			int heapMemoryInMB,
			int directMemoryInMB,
			int nativeMemoryInMB,
			int stateSizeInMB,
			int managedMemoryInMB,
			Resource... extendedResources); private  ResourceSpec(); }
ResourceSpec implements Serializable { public ResourceSpec merge(ResourceSpec other) { if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } ResourceSpec target = new ResourceSpec( Math.max(this.cpuCores, other.cpuCores), this.heapMemoryInMB + other.heapMemoryInMB, this.directMemoryInMB + other.directMemoryInMB, this.nativeMemoryInMB + other.nativeMemoryInMB, this.stateSizeInMB + other.stateSizeInMB, this.managedMemoryInMB + other.managedMemoryInMB); target.extendedResources.putAll(extendedResources); for (Resource resource : other.extendedResources.values()) { target.extendedResources.merge(resource.getName(), resource, (v1, v2) -> v1.merge(v2)); } return target; } private  ResourceSpec(
			double cpuCores,
			int heapMemoryInMB,
			int directMemoryInMB,
			int nativeMemoryInMB,
			int stateSizeInMB,
			int managedMemoryInMB,
			Resource... extendedResources); private  ResourceSpec(); ResourceSpec merge(ResourceSpec other); double getCpuCores(); int getHeapMemory(); int getDirectMemory(); int getNativeMemory(); int getStateSize(); int getManagedMemory(); double getGPUResource(); Map<String, Resource> getExtendedResources(); boolean isValid(); boolean lessThanOrEqual(@Nonnull ResourceSpec other); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static Builder newBuilder(); }
ResourceSpec implements Serializable { public ResourceSpec merge(ResourceSpec other) { if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) { return UNKNOWN; } ResourceSpec target = new ResourceSpec( Math.max(this.cpuCores, other.cpuCores), this.heapMemoryInMB + other.heapMemoryInMB, this.directMemoryInMB + other.directMemoryInMB, this.nativeMemoryInMB + other.nativeMemoryInMB, this.stateSizeInMB + other.stateSizeInMB, this.managedMemoryInMB + other.managedMemoryInMB); target.extendedResources.putAll(extendedResources); for (Resource resource : other.extendedResources.values()) { target.extendedResources.merge(resource.getName(), resource, (v1, v2) -> v1.merge(v2)); } return target; } private  ResourceSpec(
			double cpuCores,
			int heapMemoryInMB,
			int directMemoryInMB,
			int nativeMemoryInMB,
			int stateSizeInMB,
			int managedMemoryInMB,
			Resource... extendedResources); private  ResourceSpec(); ResourceSpec merge(ResourceSpec other); double getCpuCores(); int getHeapMemory(); int getDirectMemory(); int getNativeMemory(); int getStateSize(); int getManagedMemory(); double getGPUResource(); Map<String, Resource> getExtendedResources(); boolean isValid(); boolean lessThanOrEqual(@Nonnull ResourceSpec other); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static Builder newBuilder(); static final ResourceSpec UNKNOWN; static final ResourceSpec DEFAULT; static final String GPU_NAME; }