2017-01-08 9 views
1

私は客観により管理オブジェクトストアの整合性をテストするためのテストケースを書いた:イテレータは同じIDを持つ2つのレコードを取得しました...それはどのように可能ですか?

@Test 
public void testCreateDuplicateWithDiffID() throws NullValueException, NotFoundException { 

    gift.setGiftedOn(Calendar.getInstance().getTime()); 

    gEndPt.create(gift); 

    int countBefore2ndCreate = OfyController.count(Gift.class); 

    // reinitialize the instanceID of the gift...now it's "different" 
    gift.initID(); 

    // got to make sure we have a new date 
    gift.setGiftedOn(Calendar.getInstance().getTime()); 

    // attempt to "re-create" the same instance 
    gEndPt.create(gift); 

    int countAfterCreate = OfyController.count(Gift.class); 

    // check the count...make sure it changes after the two inserts 
    assertThat("New Gift was NOT created", countAfterCreate, is(2)); 

    QueryResultIterator<Gift> iterator = OfyController.ofy().load().type(Gift.class).iterator(); 

    while (iterator.hasNext()){ 
     log.info(iterator.next().getInstID()); 
    } 

}

をすべてはwhileループまでの罰金です。いくつかの奇妙な理由で、イテレータは、同じレコードが表示されている(はそれだけを反復処理ではないですか、同じレコードを二回作成されたかわからない)

enter image description here

答えて

0

それはここで起こっている内容を正確に把握するのは難しいですエンティティを作成して保存し、IDを変更しようとすると決して行うべきではありません。エンティティインスタンスはセッションキャッシュに保存されるため、キャッシュから混乱する可能性があります。

このようなオブジェクトインスタンスをリサイクルする理由はありません。エンティティインスタンスのIDは決してリセットしないでください。

関連する問題