@Test public void update() throws RyaDetailsRepositoryException, CouldNotApplyMutationException { final RyaDetails originalDetails = RyaDetails.builder() .setRyaInstanceName("instanceName") .setRyaVersion("0.0.0.0") .setFreeTextDetails( new FreeTextIndexDetails(true) ) .setEntityCentricIndexDetails( new EntityCentricIndexDetails(true) ) .setTemporalIndexDetails( new TemporalIndexDetails(true) ) .setPCJIndexDetails( PCJIndexDetails.builder() .setEnabled(true) ) .setJoinSelectivityDetails( new JoinSelectivityDetails( Optional.<Date>absent() ) ) .setProspectorDetails( new ProspectorDetails( Optional.<Date>absent() )) .build(); final RyaDetailsRepository detailsRepo = mock( RyaDetailsRepository.class ); when( detailsRepo.getRyaInstanceDetails() ).thenReturn( originalDetails ); new RyaDetailsUpdater(detailsRepo).update(new RyaDetailsMutator() { @Override public RyaDetails mutate(final RyaDetails old) { return RyaDetails.builder(old) .setRyaVersion("1.1.1.1") .build(); } }); final RyaDetails mutatedDetails = RyaDetails.builder(originalDetails) .setRyaVersion("1.1.1.1") .build(); verify(detailsRepo, times(1)).update( eq(originalDetails), eq(mutatedDetails) ); }
public void update(final RyaDetailsMutator mutator) throws RyaDetailsRepositoryException, CouldNotApplyMutationException { requireNonNull(mutator); boolean updated = false; while(!updated) { try { final RyaDetails original = repo.getRyaInstanceDetails(); final RyaDetails mutated = mutator.mutate(original); repo.update(original, mutated); updated = true; } catch(final ConcurrentUpdateException e) { log.debug("Failed to update the details because another application changed them. Trying again.", e); } } }
RyaDetailsUpdater { public void update(final RyaDetailsMutator mutator) throws RyaDetailsRepositoryException, CouldNotApplyMutationException { requireNonNull(mutator); boolean updated = false; while(!updated) { try { final RyaDetails original = repo.getRyaInstanceDetails(); final RyaDetails mutated = mutator.mutate(original); repo.update(original, mutated); updated = true; } catch(final ConcurrentUpdateException e) { log.debug("Failed to update the details because another application changed them. Trying again.", e); } } } }
RyaDetailsUpdater { public void update(final RyaDetailsMutator mutator) throws RyaDetailsRepositoryException, CouldNotApplyMutationException { requireNonNull(mutator); boolean updated = false; while(!updated) { try { final RyaDetails original = repo.getRyaInstanceDetails(); final RyaDetails mutated = mutator.mutate(original); repo.update(original, mutated); updated = true; } catch(final ConcurrentUpdateException e) { log.debug("Failed to update the details because another application changed them. Trying again.", e); } } } RyaDetailsUpdater(final RyaDetailsRepository repo); }
RyaDetailsUpdater { public void update(final RyaDetailsMutator mutator) throws RyaDetailsRepositoryException, CouldNotApplyMutationException { requireNonNull(mutator); boolean updated = false; while(!updated) { try { final RyaDetails original = repo.getRyaInstanceDetails(); final RyaDetails mutated = mutator.mutate(original); repo.update(original, mutated); updated = true; } catch(final ConcurrentUpdateException e) { log.debug("Failed to update the details because another application changed them. Trying again.", e); } } } RyaDetailsUpdater(final RyaDetailsRepository repo); void update(final RyaDetailsMutator mutator); }
RyaDetailsUpdater { public void update(final RyaDetailsMutator mutator) throws RyaDetailsRepositoryException, CouldNotApplyMutationException { requireNonNull(mutator); boolean updated = false; while(!updated) { try { final RyaDetails original = repo.getRyaInstanceDetails(); final RyaDetails mutated = mutator.mutate(original); repo.update(original, mutated); updated = true; } catch(final ConcurrentUpdateException e) { log.debug("Failed to update the details because another application changed them. Trying again.", e); } } } RyaDetailsUpdater(final RyaDetailsRepository repo); void update(final RyaDetailsMutator mutator);  }