SDN4 - 删除操作后,存储库查询未访问数据库并在加载时返回过时数据

时间:2015-10-17 15:16:28

标签: spring-data-neo4j-4 neo4j-ogm

我的一个单元测试似乎是返回过时的数据。该测试正在测试我是否可以从事件中删除某些故障单类型(已售出故障单)。我留下了评论,以显示代码中出现的问题。

            @Test
            public void deleteTicketTypeByDomainSpecificId() { 
                logger.info("Given we have a member with an event that has some ticket types");
                Member member = createMember();
                Event event = eventService.createEvent("My cool new event", member);
                String eventId = event.getDomainSpecificId();

                // create our first ticket type
                TicketTypeCreator ticketTypeCreator = ticketTypeService.new TicketTypeCreator();
                ticketTypeCreator.setUiId(UniqueIDGenerator.randomID());
                ticketTypeCreator.setTicketTypeName("Seated ticket");
                ticketTypeCreator.setTicketTypeUrl("http://www.joesevents.com/joe");
                ticketTypeCreator.setTicketTypePrice("58.00");
                ticketTypeCreator.setEvent(event);
                TicketType ticketType1 = ticketTypeCreator.create();

//在localhost上可以看到一种票证类型:7474(我们期望的)

                // create our second ticket type
                ticketTypeCreator.setUiId(UniqueIDGenerator.randomID());
                ticketTypeCreator.setTicketTypeName("Standing ticket");
                ticketTypeCreator.setTicketTypeUrl("http://www.jillsevents.com");
                ticketTypeCreator.setTicketTypePrice("38.00");
                ticketTypeCreator.setEvent(event);
                ticketTypeCreator.create();

//在localhost上可以看到两种票证类型:7474(我们期望的)

                logger.info("When we delete a ticketType");
                ticketTypeService.deleteTicketTypeByDomainSpecificId(ticketType1.getDomainSpecificId());

//在localhost上可以看到一种票证类型:7474(我们期望的)

                // This code loads only one ticket type which is what we expect
                Iterable<TicketType> ticketTypes = ticketTypeService.findAll();
                int count = 0;
                for (TicketType ticketType : ticketTypes) { 
                    count ++;
                }
                assertThat(count, is(equalTo(1)));

                logger.info("And the event should have one less ticket type type after we reload it");

//此代码加载两种故障单类型,即使端口7474上的数据库显示1种故障单类型,即使前一代码仅返回1种故障单类型。

                event = eventService.loadEventByDomainSpecificId(eventId);
                Set<TicketType> ticketTypes2 = event.getTicketTypes();
                for (TicketType ticketType : ticketTypes2) { 
                    System.out.println(ticketType.getTicketTypeName());
                }
                assertThat(event.getTicketTypes().size(), is(equalTo(1)));
            }

eventService.loadEventByDomainSpecificId(eventId)是一个@Service,它只调用下面显示的存储库。服务没有缓存。

@Repository
public interface EventRepository extends GraphRepository<Event>{

    public Event findByDomainSpecificId(String domainSpecificId);

}

0 个答案:

没有答案