2016-12-22 1 views
6

LocalDatastoreServiceTestConfig을 구성하여 복합 색인이 필요할 경우 (예 : 여러 속성에 대한 정렬이 포함 된 검색어) 쿼리가 실패하도록 구성하고 싶습니다. 이것을 할 수있는 방법이 있습니까?복합 색인이 필요한 경우 Java Google App Engine SDK에 대한 테스트를 구성하는 방법이 있습니까?

나는 new LocalDatastoreServiceTestConfig().setNoIndexAutoGen(true)을 시도했지만 아무런 효과가 없었습니다.

의 (a corresponding way to do this with the Python SDK 있습니다.)

I에 의해 가정

답변

1

"실패"당신이 또는 이와 유사한 "예외가 발생"을 의미한다. 그렇다면 WEB-INF/datastore-indexes.xmlautoGenerate 속성을 false로 설정해야합니다.

WEB-INF/datastore-indexes.xml : 복합 인덱스가 예외를 던질 필요로하는 쿼리를 만들 것입니다 false로 autoGenerate 설정

<datastore-indexes autoGenerate="false"> 
</datastore-indexes> 

. 예제 코드 :

SEVERE: com.google.appengine.api.datastore.DatastoreNeedIndexException: Query com.google.appengine.api.datastore.dev.LocalCompositeIndexManager$IndexComponentsO 
[email protected] requires a composite index that is not defined. You must update C:\appengine-java-sdk\dev\core1\war\WEB-INF\datastore-indexes.xml or enable au 
toGenerate to have it automatically added. 
The suggested index for this query is: 
    <datastore-index kind="Action" ancestor="false" source="manual"> 
     <property name="encrypter" direction="asc"/> 
     <property name="requester" direction="asc"/> 
     <property name="time" direction="desc"/> 
    </datastore-index> 

자세한 내용은 datastore-indexes.xml reference를 참조하십시오

try { 
    Query q = new Query("Action") 
      .addSort("encrypter", Query.SortDirection.ASCENDING) 
      .addSort("requester", Query.SortDirection.ASCENDING) 
      .addSort("time", Query.SortDirection.DESCENDING); 

    //...snip... 

} catch (Exception e) { 
    log.severe(e.toString()); 
} 

나는 예상대로 기록 예외를이 테스트를하고 있어요.

+0

단원 테스트에서이 오류가 발생하는 예가 있습니까? 이 설정을 가지고 있으며 dev 서버에서 실행 중일 때 쿼리가 실패하지만 동일한 쿼리를 실행하는 테스트가 실패하지는 않습니다. 아마도 테스트를 위해 파일을 읽도록 구성해야하는 다른 것이있을 것입니다. –

+0

재생산을 위해 테스트 작성 방법에 대한 최소한의 실무 사례를 제공 할 수 있습니까? 또는 다음과 같이 정의 된 XmlDocument 개체에 대해 쿼리를 실행 해보십시오. 'XmlDocument doc = new XmlDocument(); doc.Load (xmlFilePath);' – Alex

관련 문제