/** 정해진 시간에 호출이 완료되는 경우 timeout없이 올바른 리턴값을 줘야한다. */ @Test public void shouldReturnValueWithoutTimeout() { ExecuteFunction<String, String> func = new ExecuteFunction<String, String>() { public String apply(String t) { try { Thread.sleep(100); } catch (Exception e) { } return t; } }; String expected = "hello"; ExecuteResult<String> result = timeoutSvc.executeInTransaction(func, expected, 1000); assertThat(result.getReturnObject()).isEqualTo(expected); }
/** 지정된 시간 내에 처리가 완료되면 트랜잭션은 commit이 되야 한다. */ @Test public void shouldCommitWhenExecutedInTime() { ExecuteFunction<Employee, Integer> func = new ExecuteFunction<Employee, Integer>() { public Integer apply(Employee emp) { return empService.addNewEmployee(emp); } }; empService.deleteById("committedInTime"); Employee emp = new Employee(); emp.setId("committedInTime"); emp.setName("committedInTime"); ExecuteResult<Integer> result = timeoutSvc.<Employee, Integer>executeInTransaction(func, emp, 1000); assertThat(result.getReturnObject()).isEqualTo(1); Employee actual = empService.findById("committedInTime"); assertThat(actual).isNotNull(); assertThat(actual.getId()).isEqualTo("committedInTime"); }