Is there a way to configure tests for the Java Google App Engine Java SDK if a composite index is needed?

I would like to configure LocalDatastoreServiceTestConfig in such a way that requests will fail if a composite index is needed (for example, a request sorted by several properties). Is there any way to do this?

I tried new LocalDatastoreServiceTestConfig().setNoIndexAutoGen(true) , but this did not affect.

(There is an appropriate way to do this using the Python SDK .)

+6
source share
1 answer

I suppose that "crashing" means throwing an exception or something like that. If so, you should set the autoGenerate attribute in WEB-INF/datastore-indexes.xml to false.

Example WEB-INF/datastore-indexes.xml :

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

Setting autoGenerate to false will make a query that requires the composite index to throw an exception. Code example:

 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()); } 

I tested this and got an exception logged as expected:

 SEVERE: com.google.appengine.api.datastore.DatastoreNeedIndexException: Query com.google.appengine.api.datastore.dev.LocalCompositeIndexManager$IndexComponentsO nlyQuery@f9f81ad3 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> 

See datastore-indexes.xml for more information.

+1
source

Source: https://habr.com/ru/post/1013440/


All Articles