subroutine test_back_and_forth(this)
use pFIO_ArrayReferenceMod
class (MpiTestMethod), intent(inout) :: this
integer :: comm
type (MpiSocket) :: s1, s2
class (AbstractMessage), allocatable :: message
type (ProtocolParser), target :: parser
integer :: rank
type (ArrayReference) :: ref
integer, target :: fake_data
enum, bind(c)
enumerator :: collection1, collection2
end enum
enum, bind(c)
enumerator :: request_A, request_B, request_C
end enum
comm = this%getMpiCommunicator()
parser = ProtocolParser()
rank = this%getProcessRank()
ref = ArrayReference(fake_data)
select case (rank)
case (0) ! server
s1 = MpiSocket(comm, 2, parser)
s2 = MpiSocket(comm, 3, parser)
allocate(message, source=s1%receive())
@assertEqual(PrefetchData_ID, message%get_type_id())
select type (message)
type is (PrefetchDataMessage)
@assertEqual(collection1, message%collection_id)
end select
call s1%send(IdMessage(request_B))
deallocate(message)
allocate(message, source=s2%receive())
@assertEqual(PrefetchData_ID, message%get_type_id())
select type (message)
type is (PrefetchDataMessage)
@assertEqual(collection2, message%collection_id)
end select
call s2%send(IdMessage(REQUEST_C))
deallocate(message)
allocate(message, source=s1%receive())
@assertEqual(TERMINATE_ID, message%get_type_id())
deallocate(message)
allocate(message, source=s2%receive())
@assertEqual(TERMINATE_ID, message%get_type_id())
case (1)
s1 = MpiSocket(comm, 4, parser)
allocate(message, source=s1%receive())
@assertEqual(PrefetchData_ID, message%get_type_id())
select type (message)
type is (PrefetchDataMessage)
@assertEqual(collection1, message%collection_id)
end select
call s1%send(IdMessage(request_A))
deallocate(message)
allocate(message, source=s1%receive())
@assertEqual(TERMINATE_ID, message%get_type_id())
case (2)
s1 = MpiSocket(comm, 0, parser)
!call s1%send(PrefetchDataMessage(1, collection1,'foo','u', ref, start=[]))
call s1%send(PrefetchDataMessage(1, collection1,'foo','u', ref))
allocate(message, source=s1%receive())
@assertEqual(ID_ID, message%get_type_id())
select type (message)
type is (IdMessage)
@assertEqual(request_B, message%id)
end select
call s1%send(TerminateMessage())
case (3)
s1 = MpiSocket(comm, 0, parser)
!call s1%send(PrefetchDataMessage(2, collection2,'foo','v', ref, start=[]))
call s1%send(PrefetchDataMessage(2, collection2,'foo','v', ref))
allocate(message, source=s1%receive())
@assertEqual(ID_ID, message%get_type_id())
select type (message)
type is (IdMessage)
@assertEqual(request_C, message%id)
end select
call s1%send(TerminateMessage())
case (4)
s1 = MpiSocket(comm, 1, parser)
!call s1%send(PrefetchDataMessage(3, collection1,'foo','w', ref, start=[]))
call s1%send(PrefetchDataMessage(3, collection1,'foo','w', ref))
allocate(message, source=s1%receive())
@assertEqual(ID_ID, message%get_type_id())
select type (message)
type is (IdMessage)
@assertEqual(request_A, message%id)
end select
call s1%send(TerminateMessage())
end select
end subroutine test_back_and_forth