def test_register_slot_sharing_group(self):
        slot_sharing_group_1 = SlotSharingGroup.builder('slot_sharing_group_1') \
            .set_cpu_cores(1.0).set_task_heap_memory_mb(100).build()
        slot_sharing_group_2 = SlotSharingGroup.builder('slot_sharing_group_2') \
            .set_cpu_cores(2.0).set_task_heap_memory_mb(200).build()
        slot_sharing_group_3 = SlotSharingGroup.builder(
            'slot_sharing_group_3').build()
        self.env.register_slot_sharing_group(slot_sharing_group_1)
        self.env.register_slot_sharing_group(slot_sharing_group_2)
        self.env.register_slot_sharing_group(slot_sharing_group_3)
        ds = self.env.from_collection(
            [1, 2, 3]).slot_sharing_group('slot_sharing_group_1')
        ds.map(lambda x: x + 1).set_parallelism(3) \
            .slot_sharing_group('slot_sharing_group_2') \
            .add_sink(self.test_sink)

        j_generated_stream_graph = self.env._j_stream_execution_environment \
            .getStreamGraph(True)
        j_resource_profile_1 = j_generated_stream_graph.getSlotSharingGroupResource(
            'slot_sharing_group_1').get()
        j_resource_profile_2 = j_generated_stream_graph.getSlotSharingGroupResource(
            'slot_sharing_group_2').get()
        j_resource_profile_3 = j_generated_stream_graph.getSlotSharingGroupResource(
            'slot_sharing_group_3')
        self.assertEqual(j_resource_profile_1.getCpuCores().getValue(), 1.0)
        self.assertEqual(
            MemorySize(j_memory_size=j_resource_profile_1.getTaskHeapMemory()),
            MemorySize.of_mebi_bytes(100))
        self.assertEqual(j_resource_profile_2.getCpuCores().getValue(), 2.0)
        self.assertEqual(
            MemorySize(j_memory_size=j_resource_profile_2.getTaskHeapMemory()),
            MemorySize.of_mebi_bytes(200))
        self.assertFalse(j_resource_profile_3.isPresent())
 def test_build_slot_sharing_group_with_illegal_config(self):
     with self.assertRaises(Exception):
         SlotSharingGroup.builder("slot_sharing_group") \
             .set_cpu_cores(1.0) \
             .set_task_heap_memory(MemorySize(bytes_size=0)) \
             .set_task_off_heap_memory_mb(10) \
             .build()
 def test_build_slot_sharing_group_with_specific_resource(self):
     name = 'slot_sharing_group'
     heap_memory = MemorySize.of_mebi_bytes(100)
     off_heap_memory = MemorySize.of_mebi_bytes(200)
     managed_memory = MemorySize.of_mebi_bytes(300)
     slot_sharing_group = SlotSharingGroup.builder(name) \
         .set_cpu_cores(1.0) \
         .set_task_heap_memory(heap_memory) \
         .set_task_off_heap_memory(off_heap_memory) \
         .set_managed_memory(managed_memory) \
         .set_external_resource('gpu', 1.0) \
         .build()
     self.assertEqual(slot_sharing_group.get_name(), name)
     self.assertEqual(slot_sharing_group.get_cpu_cores(), 1.0)
     self.assertEqual(slot_sharing_group.get_task_heap_memory(), heap_memory)
     self.assertEqual(slot_sharing_group.get_task_off_heap_memory(), off_heap_memory)
     self.assertEqual(slot_sharing_group.get_managed_memory(), managed_memory)
     self.assertEqual(slot_sharing_group.get_external_resources(), {'gpu': 1.0})