本文整理汇总了Java中com.redhat.lightblue.crud.CRUDUpdateResponse类的典型用法代码示例。如果您正苦于以下问题:Java CRUDUpdateResponse类的具体用法?Java CRUDUpdateResponse怎么用?Java CRUDUpdateResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CRUDUpdateResponse类属于com.redhat.lightblue.crud包,在下文中一共展示了CRUDUpdateResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updatingButNotModifyingReturnsProjection
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
@Test
public void updatingButNotModifyingReturnsProjection() throws Exception {
// issue #391
EntityMetadata md = getMd("./testMetadata.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.INSERT);
ctx.add(md);
addDocument(ctx,new JsonDoc(loadJsonNode("./testdata1.json")));
controller.insert(ctx, projection("{'field':'_id'}"));
ctx = new TestCRUDOperationContext(CRUDOperation.UPDATE);
ctx.add(md);
// Updating an array field will force use of IterateAndupdate
CRUDUpdateResponse upd = controller.update(ctx, query("{'field':'field3','op':'>','rvalue':0}"),
update("{ '$set': { 'field7.0.elemf1' : 'value0_1' } }"), projection("{'field':'_id'}"));
Assert.assertEquals(IterateAndUpdate.class, ctx.getProperty(MongoCRUDController.PROP_UPDATER).getClass());
Assert.assertEquals(0, upd.getNumUpdated());
Assert.assertEquals(1, upd.getNumMatched());
Assert.assertEquals(0, upd.getNumFailed());
Assert.assertTrue(ctx.getDocumentStream().hasNext());
}
示例2: updateTest_nullReqField
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
@Test
public void updateTest_nullReqField() throws Exception {
EntityMetadata md = getMd("./testMetadata-requiredFields2.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.INSERT);
ctx.add(md);
JsonDoc doc = new JsonDoc(loadJsonNode("./testdata1.json"));
doc.modify(new Path("field1"), JsonNodeFactory.instance.nullNode(), false);
Projection projection = projection("{'field':'_id'}");
addDocument(ctx,doc);
CRUDInsertionResponse response = controller.insert(ctx, projection);
ctx = new TestCRUDOperationContext(CRUDOperation.UPDATE);
ctx.add(md);
CRUDUpdateResponse upd = controller.update(ctx, query("{'field':'field2','op':'=','rvalue':'f2'}"),
update(" {'$set' : {'field3':3 }}"),
projection("{'field':'*','recursive':1}"));
Assert.assertEquals(0, upd.getNumUpdated());
Assert.assertEquals(1, upd.getNumFailed());
Assert.assertEquals(1, getDataErrors(ctx).size());
Assert.assertEquals(1, getDataErrors(ctx).get(0).getErrors().size());
Error error = getDataErrors(ctx).get(0).getErrors().get(0);
Assert.assertEquals("crud:Required", error.getErrorCode());
Assert.assertEquals("field1", error.getMsg());
}
示例3: testMigrationUpdate
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
@Test
public void testMigrationUpdate() throws Exception {
EntityMetadata md = getMd("./migrationJob.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext("migrationJob", CRUDOperation.INSERT);
ctx.add(md);
JsonDoc doc = new JsonDoc(loadJsonNode("./job1.json"));
Projection projection = projection("{'field':'_id'}");
addDocument(ctx,doc);
System.out.println("Write doc:" + doc);
CRUDInsertionResponse insresponse = controller.insert(ctx, projection);
ctx = new TestCRUDOperationContext("migrationJob", CRUDOperation.UPDATE);
ctx.add(md);
CRUDUpdateResponse upd = controller.update(ctx, query("{'field':'_id','op':'=','rvalue':'termsAcknowledgementJob_6264'}"),
update("[{'$append':{'jobExecutions':{}}},{'$set':{'jobExecutions.-1.ownerName':'hystrix'}},{'$set':{'jobExecutions.-1.hostName':'$(hostname)'}},{'$set':{'jobExecutions.-1.pid':'[email protected]'}},{'$set':{'jobExecutions.-1.actualStartDate':'20150312T19:19:00.700+0000'}},{'$set':{'jobExecutions.-1.actualEndDate':'$null'}},{'$set':{'jobExecutions.-1.completedFlag':false}},{'$set':{'jobExecutions.-1.processedDocumentCount':0}},{'$set':{'jobExecutions.-1.consistentDocumentCount':0}},{'$set':{'jobExecutions.-1.inconsistentDocumentCount':0}},{'$set':{'jobExecutions.-1.overwrittenDocumentCount':0}}]"),
projection("{'field':'*','recursive':1}"));
List<DocCtx> documents=streamToList(ctx);
Assert.assertEquals(1, documents.size());
Assert.assertEquals(2, documents.get(0).getOutputDocument().get(new Path("jobExecutions")).size());
}
示例4: updateQueryFieldRoleTest
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
@Test
public void updateQueryFieldRoleTest() throws Exception {
UpdateRequest req = new UpdateRequest();
req.setEntityVersion(new EntityVersion("test", "1.0"));
req.setReturnFields(null);
req.setQuery(new ValueComparisonExpression(new Path("field1"), BinaryComparisonOperator._eq, new Value("x")));
req.setClientId(new RestClientIdentification(Arrays.asList("test-update")));
mockCrudController.updateResponse = new CRUDUpdateResponse();
Response response = mediator.update(req);
Assert.assertEquals(OperationStatus.ERROR, response.getStatus());
req.setQuery(new ValueComparisonExpression(new Path("field2"), BinaryComparisonOperator._eq, new Value("x")));
response = mediator.update(req);
Assert.assertEquals(OperationStatus.COMPLETE, response.getStatus());
}
示例5: updateTest_SingleFailure
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
@Test
public void updateTest_SingleFailure() throws Exception {
EntityMetadata md = getMd("./testMetadata.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.INSERT);
coll.createIndex(new BasicDBObject("field1", 1),"unique_test_index", true);
ctx.add(md);
// Generate some docs
List<JsonDoc> docs = new ArrayList<>();
int numDocs = 20;
for (int i = 0; i < numDocs; i++) {
JsonDoc doc = new JsonDoc(loadJsonNode("./testdata1.json"));
doc.modify(new Path("field1"), nodeFactory.textNode("doc" + i), false);
doc.modify(new Path("field3"), nodeFactory.numberNode(i), false);
docs.add(doc);
}
addDocuments(ctx,docs);
CRUDInsertionResponse response = controller.insert(ctx, projection("{'field':'_id'}"));
try (DBCursor c = coll.find(null)) {
Assert.assertEquals(numDocs, c.count());
}
Assert.assertEquals(ctx.getInputDocumentsWithoutErrors().size(), response.getNumInserted());
ctx = new TestCRUDOperationContext(CRUDOperation.UPDATE);
ctx.add(md);
CRUDUpdateResponse upd = controller.update(ctx, query("{'field':'field3','op':'>','rvalue':-1}"),
update("{ '$set': { 'field1' : '100' } }"),
projection("{'field':'_id'}"));
assertEquals(1, upd.getNumUpdated());
assertEquals(20, upd.getNumMatched());
assertEquals(19, upd.getNumFailed());
List<DocCtx> documents=streamToList(ctx);
Assert.assertNotNull(documents.get(0).getResultMetadata());
Assert.assertNotNull(documents.get(0).getResultMetadata().getDocumentVersion());
}
示例6: update_MultiBatch
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
@Test
public void update_MultiBatch() throws Exception {
int batch = controller.getBatchSize() + 2;
EntityMetadata md = getMd("./testMetadata.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.INSERT);
ctx.add(md);
// Generate some docs
List<JsonDoc> docs = new ArrayList<>();
for (int i = 0; i < batch; i++) {
JsonDoc doc = new JsonDoc(loadJsonNode("./testdata1.json"));
doc.modify(new Path("field1"), nodeFactory.textNode("doc" + i), false);
doc.modify(new Path("field3"), nodeFactory.numberNode(i), false);
docs.add(doc);
}
addDocuments(ctx,docs);
CRUDInsertionResponse response = controller.insert(ctx, projection("{'field':'_id'}"));
try (DBCursor c = coll.find(null)) {
Assert.assertEquals(batch, c.count());
}
Assert.assertEquals(ctx.getInputDocumentsWithoutErrors().size(), response.getNumInserted());
ctx = new TestCRUDOperationContext(CRUDOperation.UPDATE);
ctx.add(md);
CRUDUpdateResponse upd = controller.update(ctx, query("{'field':'field3','op':'>','rvalue':-1}"),
update("{ '$set': { 'field1' : '100' } }"),
projection("{'field':'_id'}"));
// just make sure all get inserted when we're multi batching. difficult to spy from here
List<DocCtx> documents=streamToList(ctx);
assertEquals(batch, upd.getNumUpdated());
Assert.assertNotNull(documents.get(0).getResultMetadata());
Assert.assertNotNull(documents.get(0).getResultMetadata().getDocumentVersion());
}
示例7: updateDocuments_NoLimits
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
/**
* A baseline test, no limits on result set size.
*
* @throws Exception
*/
@Test
public void updateDocuments_NoLimits() throws Exception {
setupTestDataAndMetadata();
insertDocs(10);
TestCRUDOperationContext ctx = new TestCRUDOperationContext("test", CRUDOperation.UPDATE);
ctx.add(emd);
ctx.getFactory().setMaxResultSetSizeForWritesB(-1);
CRUDUpdateResponse response = controller.update(ctx,
query("{'field':'field1','op':'$eq','rvalue':'f1'}"),
update("{ '$set': { 'field2' : 'f2-updated' } }"),
projection("{'field':'*'}"));
Assert.assertEquals(10, response.getNumMatched());
Assert.assertEquals(10, response.getNumUpdated());
DBCursor cursor = db.getCollection("data").find();
assertTrue(cursor.hasNext());
cursor.forEach(obj -> {
String field2value = ((DBObject) obj).get("field2").toString();
assertEquals("f2-updated", field2value);
});
List<DocCtx> documents=streamToList(ctx);
Assert.assertEquals(10, documents.size());
Assert.assertTrue(ctx.getErrors().isEmpty());
}
示例8: updateDocuments_LimitNotExceeded
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
/**
* Limit is above the needs of this update.
*
* @throws Exception
*/
@Test
public void updateDocuments_LimitNotExceeded() throws Exception {
setupTestDataAndMetadata();
insertDocs(10);
TestCRUDOperationContext ctx = new TestCRUDOperationContext("test", CRUDOperation.UPDATE);
ctx.add(emd);
// 74 docs is 25798, 11 docs is ~3835B
ctx.getFactory().setMaxResultSetSizeForWritesB(3835);
CRUDUpdateResponse response = controller.update(ctx,
query("{'field':'field1','op':'$eq','rvalue':'f1'}"),
update("{ '$set': { 'field2' : 'f2-updated' } }"),
projection("{'field':'*'}"));
Assert.assertEquals(10, response.getNumMatched());
Assert.assertEquals(10, response.getNumUpdated());
DBCursor cursor = db.getCollection("data").find();
assertTrue(cursor.hasNext());
cursor.forEach(obj -> {
String field2value = ((DBObject) obj).get("field2").toString();
assertEquals("f2-updated", field2value);
});
List<DocCtx> documents=streamToList(ctx);
Assert.assertEquals(10, documents.size());
Assert.assertTrue(ctx.getErrors().isEmpty());
}
示例9: updateDocuments_LimitExceededByHookManager
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
/**
* Hook processing exceeds threshold. The size of the list of docs accumulated for this update
* does not.
*
* @throws Exception
*/
@Test
public void updateDocuments_LimitExceededByHookManager() throws Exception {
int count = MongoCRUDController.DEFAULT_BATCH_SIZE+10;
setupTestDataAndMetadataWithHook();
insertDocs(count);
TestCRUDOperationContext ctx = new TestCRUDOperationContext("test", CRUDOperation.UPDATE);
ctx.add(emd);
// 25798 B is the ctx.inputDocuments size after update, but before hooks
ctx.getFactory().setMaxResultSetSizeForWritesB(25798+10);
CRUDUpdateResponse response = controller.update(ctx,
query("{'field':'field1','op':'$eq','rvalue':'f1'}"),
update("{ '$set': { 'field2' : 'f2-updated' } }"),
projection("{'field':'*'}"));
// expecting memory limit to kick in during hook processing
Assert.assertEquals(1, ctx.getErrors().size());
Assert.assertEquals(Response.ERR_RESULT_SIZE_TOO_LARGE, ctx.getErrors().get(0).getErrorCode());
// all updates applied successfully
Assert.assertEquals(count, response.getNumMatched());
Assert.assertEquals(count, response.getNumUpdated());
Assert.assertEquals(0, response.getNumFailed());
DBCursor cursor = db.getCollection("data").find();
int i = 0;
while (cursor.hasNext()) {
String field2value = cursor.next().get("field2").toString();
assertEquals("Expecting first batch to be updated successfully", "f2-updated", field2value);
i++;
}
Assert.assertEquals(count, i);
}
示例10: updateRoleTest
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
@Test
public void updateRoleTest() throws Exception {
UpdateRequest req = new UpdateRequest();
req.setEntityVersion(new EntityVersion("test", "1.0"));
req.setReturnFields(null);
mdManager.md.getAccess().getUpdate().setRoles("role1");
mockCrudController.updateResponse = new CRUDUpdateResponse();
Response response = mediator.update(req);
Assert.assertEquals(OperationStatus.ERROR, response.getStatus());
Assert.assertEquals(0, response.getModifiedCount());
Assert.assertEquals(0, response.getMatchCount());
Assert.assertEquals(0, response.getDataErrors().size());
Assert.assertEquals(1, response.getErrors().size());
Assert.assertEquals(CrudConstants.ERR_NO_ACCESS, response.getErrors().get(0).getErrorCode());
mdManager.md.getAccess().getUpdate().setRoles("anyone");
mockCrudController.updateResponse.setNumUpdated(1);
mockCrudController.updateResponse.setNumMatched(1);
response = mediator.update(req);
Assert.assertEquals(OperationStatus.COMPLETE, response.getStatus());
Assert.assertEquals(1, response.getModifiedCount());
Assert.assertEquals(1, response.getMatchCount());
Assert.assertEquals(0, response.getDataErrors().size());
Assert.assertEquals(0, response.getErrors().size());
}
示例11: updateResultSetTooLargeTest
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
@Test
public void updateResultSetTooLargeTest() throws Exception {
final JsonNode sampleDoc = loadJsonNode("./sample1.json");
UpdateRequest req = new UpdateRequest();
req.setEntityVersion(new EntityVersion("test", "1.0"));
mdManager.md.getAccess().getUpdate().setRoles("anyone");
mockCrudController.updateResponse = new CRUDUpdateResponse();
mockCrudController.updateCb=ctx->{
ArrayList<DocCtx> docs=new ArrayList<>();
for(int i=0;i<10;i++) {
docs.add(new DocCtx(new JsonDoc(sampleDoc),getRmd(Integer.toString(i))));
}
ctx.setInputDocuments(docs);
};
mediator.factory.setMaxResultSetSizeForWritesB(11000);
Response response = mediator.update(req); // max result set size exceeded
Assert.assertEquals(OperationStatus.ERROR, response.getStatus());
Assert.assertEquals("Expecting entity data size = 0", 0, JsonUtils.size(response.getEntityData()));
Assert.assertEquals("Expecting one error in response", 1, response.getErrors().size());
Assert.assertEquals("crud:ResultSizeTooLarge", response.getErrors().get(0).getErrorCode());
Assert.assertEquals("11290B > 11000B", response.getErrors().get(0).getMsg());
}
示例12: updateTest_PartialFailure
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
@Test
public void updateTest_PartialFailure() throws Exception {
EntityMetadata md = getMd("./testMetadata-requiredFields.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.INSERT);
ctx.add(md);
// Generate some docs
List<JsonDoc> docs = new ArrayList<>();
int numDocs = 20;
for (int i = 0; i < numDocs; i++) {
JsonDoc doc = new JsonDoc(loadJsonNode("./testdata1.json"));
doc.modify(new Path("field1"), nodeFactory.textNode("doc" + i), false);
doc.modify(new Path("field3"), nodeFactory.numberNode(i), false);
docs.add(doc);
}
addDocuments(ctx,docs);
CRUDInsertionResponse response = controller.insert(ctx, projection("{'field':'_id'}"));
try (DBCursor c = coll.find(null)) {
Assert.assertEquals(numDocs, c.count());
}
Assert.assertEquals(ctx.getInputDocumentsWithoutErrors().size(), response.getNumInserted());
// Add element to array
ctx = new TestCRUDOperationContext(CRUDOperation.UPDATE);
ctx.add(md);
CRUDUpdateResponse upd = controller.update(ctx, query("{'field':'field1','op':'=','rvalue':'doc1'}"),
update("[ {'$append' : {'field7':{}} }, { '$set': { 'field7.-1.elemf1':'test'} } ]"),
projection("{'field':'*','recursive':1}"));
List<DocCtx> documents=streamToList(ctx);
Assert.assertEquals(1, upd.getNumUpdated());
Assert.assertEquals(0, upd.getNumFailed());
Assert.assertEquals(1, documents.size());
Assert.assertEquals(3, documents.get(0).getOutputDocument().get(new Path("field7")).size());
// Add another element, with violated constraint
ctx = new TestCRUDOperationContext(CRUDOperation.UPDATE);
ctx.add(md);
upd = controller.update(ctx, query("{'field':'field1','op':'=','rvalue':'doc1'}"),
update("[ {'$append' : {'field7':{}} }, { '$set': { 'field7.-1.elemf2':'$null'} } ]"),
projection("{'field':'*','recursive':1}"));
Assert.assertEquals(0, upd.getNumUpdated());
Assert.assertEquals(1, upd.getNumFailed());
}
示例13: updateInaccessibleFieldReturnsError
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
@Test
public void updateInaccessibleFieldReturnsError() throws Exception {
// define metadata with a field that cannot be updated
EntityMetadata entityMetadata = new EntityMetadata("test");
entityMetadata.setVersion(new Version("1.0.0", null, null));
entityMetadata.setStatus(MetadataStatus.ACTIVE);
entityMetadata.setDataStore(new MongoDataStore(null, null, "test"));
SimpleField idField = new SimpleField("_id", StringType.TYPE);
List<FieldConstraint> clist = new ArrayList<>();
clist.add(new IdentityConstraint());
idField.setConstraints(clist);
entityMetadata.getFields().put(idField);
Field inaccessibleField = new SimpleField("inaccessibleField", StringType.TYPE);
inaccessibleField.getAccess().getUpdate().setRoles(Collections.singletonList("noone"));
entityMetadata.getFields().put(inaccessibleField);
entityMetadata.getFields().put(new SimpleField("objectType", StringType.TYPE));
entityMetadata.getEntityInfo().setDefaultVersion("1.0.0");
entityMetadata.getEntitySchema().getAccess().getUpdate().setRoles("anyone");
// create test document directly in mongo
DBObject testDoc = new BasicDBObject("inaccessibleField", "foo").append("objectType", "test");
db.getCollection("test").insert(testDoc);
// try to update inaccessibleField
TestCRUDOperationContext ctx = new TestCRUDOperationContext("test", CRUDOperation.UPDATE);
ctx.add(entityMetadata);
CRUDUpdateResponse response = controller.update(ctx,
QueryExpression.fromJson(JsonUtils.json("{'field': 'objectType', 'op': '=', 'rvalue': 'test'}".replaceAll("'", "\""))),
UpdateExpression.fromJson(JsonUtils.json("{'$set': { 'inaccessibleField': 'changed'}}".replaceAll("'", "\""))),
projection("{'field':'_id'}"));
Assert.assertEquals(1, response.getNumMatched());
Assert.assertEquals(0, response.getNumUpdated());
Assert.assertEquals(1, response.getNumFailed());
Assert.assertTrue("Expecting a document in the results, so the data error can be associated with it", ctx.getDocumentStream().hasNext());
DocCtx docCtx = ctx.getDocumentStream().next();
ctx.getDocumentStream().close();
Assert.assertEquals("crud:update:NoFieldAccess", docCtx.getErrors().get(0).getErrorCode());
Assert.assertEquals("[inaccessibleField]", docCtx.getErrors().get(0).getMsg());
}
示例14: updateDocuments_LimitExceeded
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
/**
* Update accumulates a list of docs which exceeds the threshold.
*
* @throws Exception
*/
@Test
public void updateDocuments_LimitExceeded() throws Exception {
// 2 batches. One batch + 10 would be updated in full, because the memory limit is enforced after commit.
int count = 2*MongoCRUDController.DEFAULT_BATCH_SIZE+10;
setupTestDataAndMetadata();
insertDocs(count);
TestCRUDOperationContext ctx = new TestCRUDOperationContext("test", CRUDOperation.UPDATE);
ctx.add(emd);
// 74 docs is 25798, 66 docs is ~22310
ctx.getFactory().setMaxResultSetSizeForWritesB(22310);
CRUDUpdateResponse response = controller.update(ctx,
query("{'field':'field1','op':'$eq','rvalue':'f1'}"),
update("{ '$set': { 'field2' : 'f2-updated' } }"),
projection("{'field':'*'}"));
Assert.assertEquals(1, ctx.getErrors().size());
Assert.assertEquals(MongoCrudConstants.ERROR_RESULT_SIZE_TOO_LARGE, ctx.getErrors().get(0).getErrorCode());
// this is misleading - 2 batches was updated successfully
// see IterateAndUpdate#enforceMemoryLimit for more info
Assert.assertEquals(0, response.getNumMatched());
Assert.assertEquals(0, response.getNumUpdated());
Assert.assertEquals(0, response.getNumFailed());
DBCursor cursor = db.getCollection("data").find();
int i = 0;
while (cursor.hasNext()) {
String field2value = cursor.next().get("field2").toString();
if (i < 2*MongoCRUDController.DEFAULT_BATCH_SIZE) {
assertEquals("Expecting first batch to be updated successfully", "f2-updated", field2value);
} else {
assertEquals("Expecting 2nd batch not to be updated, because this is where memory limit was reached", "f2", field2value);
}
i++;
}
Assert.assertEquals(count, i);
}
示例15: update
import com.redhat.lightblue.crud.CRUDUpdateResponse; //导入依赖的package包/类
/**
* Updates the documents in the resultset of a query
*
* @param ctx Operation context
* @param collection The collection in which the documents will be updated
* @param md Entity metadata
* @param response Update response
* @param query The query to search
*
* It is expected that how the documents will be updated is to be passed in
* the constructor. The implementation should run the query, update the
* documents, compute the projections of the updated documents, and update
* the operation context accordingly.1
*/
void update(CRUDOperationContext ctx,
DBCollection collection,
EntityMetadata md,
CRUDUpdateResponse response,
DBObject query);