use of com.azure.cosmos.implementation.BadRequestException in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosTransferProcessStore method update.
@Override
public void update(TransferProcess process) {
var document = new TransferProcessDocument(process, partitionKey);
try {
leaseContext.acquireLease(process.getId());
failsafeExecutor.run(() -> cosmosDbApi.saveItem(document));
leaseContext.breakLease(process.getId());
} catch (BadRequestException ex) {
throw new EdcException(ex);
}
}
use of com.azure.cosmos.implementation.BadRequestException in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosContractNegotiationStore method save.
@Override
public void save(ContractNegotiation negotiation) {
try {
leaseContext.acquireLease(negotiation.getId());
with(retryPolicy).run(() -> cosmosDbApi.saveItem(new ContractNegotiationDocument(negotiation, partitionKey)));
leaseContext.breakLease(negotiation.getId());
} catch (BadRequestException ex) {
throw new EdcException(ex);
}
}
use of com.azure.cosmos.implementation.BadRequestException in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosContractNegotiationStore method delete.
@Override
public void delete(String negotiationId) {
try {
leaseContext.acquireLease(negotiationId);
with(retryPolicy).run(() -> cosmosDbApi.deleteItem(negotiationId));
leaseContext.breakLease(negotiationId);
} catch (BadRequestException ex) {
throw new EdcException(ex);
}
}
use of com.azure.cosmos.implementation.BadRequestException in project kafka-connect-cosmosdb by microsoft.
the class CosmosDBSinkTaskTest method testPutPlainTextString.
@Test
public void testPutPlainTextString() {
Schema stringSchema = new ConnectSchema(Schema.Type.STRING);
SinkRecord record = new SinkRecord(topicName, 1, stringSchema, "nokey", stringSchema, "foo", 0L);
assertNotNull(record.value());
// Make mock connector to serialize a non-JSON payload
when(mockContainer.upsertItem(any())).then((invocation) -> {
Object item = invocation.getArgument(0);
// Will throw exception:
try {
JsonNode jsonNode = new ObjectMapper().readTree(item.toString());
assertNotNull(jsonNode);
return null;
} catch (JsonParseException jpe) {
throw new BadRequestException("Unable to serialize JSON request", jpe);
}
});
try {
testTask.put(Arrays.asList(record));
fail("Expected ConnectException on bad message");
} catch (ConnectException ce) {
} catch (Throwable t) {
fail("Expected ConnectException, but got: " + t.getClass().getName());
}
verify(mockContainer, times(1)).upsertItem("foo");
}
use of com.azure.cosmos.implementation.BadRequestException in project kafka-connect-cosmosdb by microsoft.
the class CosmosDBSinkTaskTestNotFails method testPutMapThatFailsDoesNotStopTaskWithdlq.
@Test
public void testPutMapThatFailsDoesNotStopTaskWithdlq() throws JsonProcessingException, IllegalAccessException {
FieldUtils.writeField(testTask, "context", mockContext, true);
Schema stringSchema = new ConnectSchema(Schema.Type.STRING);
Schema mapSchema = new ConnectSchema(Schema.Type.MAP);
when(mockContainer.upsertItem(any())).thenThrow(new BadRequestException("Something"));
SinkRecord record = new SinkRecord(topicName, 1, stringSchema, "nokey", mapSchema, "{", 0L);
testTask.put(List.of(record));
verify(mockContext.errantRecordReporter(), times(1)).report(any(), any());
}
Aggregations