@Test @RunWithCustomExecutor public void testOptimisticLockOK() throws InvalidParseOperationException, BadRequestException, DatabaseException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { VitamConfiguration.setOptimisticLockSleepTime(10); VitamConfiguration.setOptimisticLockRetryNumber(5); VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); assertEquals(0, vitamCollection.getCollection().countDocuments()); final ArrayNode datas = JsonHandler.createArrayNode(); datas.add(getNewDocument(GUIDFactory.newGUID().toString(), "Optimistic lock test", 3)); final Insert insert = new Insert(); insert.setData(datas); final DbRequestResult insertResult = new DbRequestSingle(vitamCollection, Collections::emptyList).execute(insert, 0, mock(DocumentValidator.class)); assertEquals(1, insertResult.getCount()); assertEquals(1, vitamCollection.getCollection().countDocuments()); insertResult.close(); CountDownLatch countDownLatch = new CountDownLatch(5); VitamThreadFactory.getInstance().newThread(() -> update(countDownLatch, 1)).start(); VitamThreadFactory.getInstance().newThread(() -> update(countDownLatch, 2)).start(); VitamThreadFactory.getInstance().newThread(() -> update(countDownLatch, 3)).start(); VitamThreadFactory.getInstance().newThread(() -> update(countDownLatch, 4)).start(); VitamThreadFactory.getInstance().newThread(() -> update(countDownLatch, 5)).start(); try { countDownLatch.await(30, TimeUnit.SECONDS); } catch (InterruptedException e) { fail("OptimisticLock KO : " + e.getMessage()); } Document document = (Document) vitamCollection.getCollection().find(new Document("Numero", 3)).first(); assertThat(document.getString("Title")).contains("thread_"); assertThat(document.getInteger("_v")).isEqualTo(5); }
public DbRequestResult execute(Select request) throws InvalidParseOperationException, DatabaseException, BadRequestException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { DynamicParserTokens parserTokens = new DynamicParserTokens(vitamCollection.getVitamDescriptionResolver(), ontologyLoader.loadOntologies()); return findDocuments(request.getFinalSelect(), parserTokens); }
DbRequestSingle { public DbRequestResult execute(Select request) throws InvalidParseOperationException, DatabaseException, BadRequestException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { DynamicParserTokens parserTokens = new DynamicParserTokens(vitamCollection.getVitamDescriptionResolver(), ontologyLoader.loadOntologies()); return findDocuments(request.getFinalSelect(), parserTokens); } }
DbRequestSingle { public DbRequestResult execute(Select request) throws InvalidParseOperationException, DatabaseException, BadRequestException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { DynamicParserTokens parserTokens = new DynamicParserTokens(vitamCollection.getVitamDescriptionResolver(), ontologyLoader.loadOntologies()); return findDocuments(request.getFinalSelect(), parserTokens); } DbRequestSingle(VitamCollection collection, OntologyLoader ontologyLoader); }
DbRequestSingle { public DbRequestResult execute(Select request) throws InvalidParseOperationException, DatabaseException, BadRequestException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { DynamicParserTokens parserTokens = new DynamicParserTokens(vitamCollection.getVitamDescriptionResolver(), ontologyLoader.loadOntologies()); return findDocuments(request.getFinalSelect(), parserTokens); } DbRequestSingle(VitamCollection collection, OntologyLoader ontologyLoader); DbRequestResult execute(Select request); DbRequestResult execute(Insert request, Integer version,
        DocumentValidator documentValidator); DbRequestResult execute(Delete request); DbRequestResult execute(Update request, DocumentValidator documentValidator); DbRequestResult execute(Update request, Integer version, DocumentValidator documentValidator); void replaceDocument(JsonNode document, String identifierValue, String identifierKey,
        VitamCollection vitamCollection); }
DbRequestSingle { public DbRequestResult execute(Select request) throws InvalidParseOperationException, DatabaseException, BadRequestException, InvalidCreateOperationException, VitamDBException, SchemaValidationException { DynamicParserTokens parserTokens = new DynamicParserTokens(vitamCollection.getVitamDescriptionResolver(), ontologyLoader.loadOntologies()); return findDocuments(request.getFinalSelect(), parserTokens); } DbRequestSingle(VitamCollection collection, OntologyLoader ontologyLoader); DbRequestResult execute(Select request); DbRequestResult execute(Insert request, Integer version,
        DocumentValidator documentValidator); DbRequestResult execute(Delete request); DbRequestResult execute(Update request, DocumentValidator documentValidator); DbRequestResult execute(Update request, Integer version, DocumentValidator documentValidator); void replaceDocument(JsonNode document, String identifierValue, String identifierKey,
        VitamCollection vitamCollection);  }