@Test
  public void test_update_rollback() {
    DbConfigWorker w =
        new DbConfigWorker(_cfgMaster.getDbSource(), _cfgMaster.getIdentifierScheme()) {
          @Override
          protected String sqlInsertConfig() {
            return "INSERT"; // bad sql
          }
        };
    final ConfigDocument<Identifier> base =
        _cfgMaster.get(UniqueIdentifier.of("DbCfg", "101", "0"), Identifier.class);
    UniqueIdentifier uid = UniqueIdentifier.of("DbCfg", "101", "0");
    ConfigDocument<Identifier> input = new ConfigDocument<Identifier>(Identifier.class);
    input.setUniqueId(uid);
    input.setName("Name");
    input.setValue(Identifier.of("A", "B"));
    try {
      w.update(input);
      Assert.fail();
    } catch (BadSqlGrammarException ex) {
      // expected
    }
    final ConfigDocument<Identifier> test =
        _cfgMaster.get(UniqueIdentifier.of("DbCfg", "101", "0"), Identifier.class);

    assertEquals(base, test);
  }
  @Test
  public void basicOperation() throws Exception {

    CalculationJobSpecification spec =
        new CalculationJobSpecification(
            UniqueIdentifier.of("Test", "ViewProcess"), "config", 1L, 1L);
    CalculationJobResult result =
        new CalculationJobResult(
            spec, 500, Collections.<CalculationJobResultItem>emptyList(), "localhost");

    TestDependencyGraphExecutor<CalculationJobResult> delegate =
        new TestDependencyGraphExecutor<CalculationJobResult>(result);

    DependencyGraph graph = new DependencyGraph("foo");

    BatchResultWriter writer = mock(BatchResultWriter.class);
    when(writer.getGraphToExecute(graph)).thenReturn(graph);

    BatchResultWriterExecutor executor = new BatchResultWriterExecutor(writer, delegate);

    Future<Object> future = executor.execute(graph, null);
    assertNotNull(future);
    future.get();

    verify(writer).getGraphToExecute(graph);
    verify(writer).write(result, graph);
  }
Ejemplo n.º 3
0
 // -------------------------------------------------------------------------
 public static URI uriViewProcess(URI baseUri, UniqueIdentifier viewProcessId) {
   // WARNING: '/' characters could well appear in the view name
   // There is a bug(?) in UriBuilder where, even though segment() is meant to treat the item as a
   // single path segment
   // and therefore encode '/' characters, it does not encode '/' characters which come from a
   // variable substitution.
   return UriBuilder.fromUri(baseUri).path("processes").segment(viewProcessId.toString()).build();
 }
 /**
  * Gets the best available position id.
  *
  * @param overrideId the override id, null derives the result from the data
  * @return the id, may be null
  */
 public String getBestPositionUriId(final UniqueIdentifier overrideId) {
   if (overrideId != null) {
     return overrideId.toLatest().toString();
   }
   return getPosition() != null
       ? getPosition().getUniqueId().toLatest().toString()
       : getUriPositionId();
 }
Ejemplo n.º 5
0
 /**
  * Gets the best available holiday id.
  *
  * @param overrideId the override id, null derives the result from the data
  * @return the id, may be null
  */
 public String getBestHolidayUriId(final UniqueIdentifier overrideId) {
   if (overrideId != null) {
     return overrideId.toLatest().toString();
   }
   return getHoliday() != null
       ? getHoliday().getUniqueId().toLatest().toString()
       : getUriHolidayId();
 }
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void test_update_notLatestVersion() {
   UniqueIdentifier uid = UniqueIdentifier.of("DbCfg", "201", "0");
   ConfigDocument<Identifier> doc = new ConfigDocument<Identifier>(Identifier.class);
   doc.setUniqueId(uid);
   doc.setName("Name");
   doc.setValue(Identifier.of("A", "B"));
   _cfgMaster.update(doc);
 }
 @Test(expectedExceptions = DataNotFoundException.class)
 public void test_update_notFound() {
   UniqueIdentifier uid = UniqueIdentifier.of("DbCfg", "0", "0");
   ConfigDocument<Identifier> doc = new ConfigDocument<Identifier>(Identifier.class);
   doc.setUniqueId(uid);
   doc.setName("Name");
   doc.setValue(Identifier.of("A", "B"));
   _cfgMaster.update(doc);
 }
Ejemplo n.º 8
0
 // -------------------------------------------------------------------------
 @Path(PATH_CLIENTS + "/{viewClientId}")
 public DataViewClientResource getViewClient(
     @Context UriInfo uriInfo, @PathParam("viewClientId") String viewClientIdString) {
   UniqueIdentifier viewClientId = UniqueIdentifier.parse(viewClientIdString);
   DataViewClientResource viewClientResource = _createdViewClients.get(viewClientId);
   if (viewClientResource != null) {
     return viewClientResource;
   }
   ViewClient viewClient = _viewProcessor.getViewClient(viewClientId);
   URI viewProcessorUri = getViewProcessorUri(uriInfo);
   return createViewClientResource(viewClient, viewProcessorUri);
 }
  @Test
  public void test_update_nameChangeNullValue() {
    Instant now = Instant.now(_cfgMaster.getTimeSource());

    UniqueIdentifier uid = UniqueIdentifier.of("DbCfg", "101", "0");
    ConfigDocument<Identifier> base = _cfgMaster.get(uid, Identifier.class);
    ConfigDocument<Identifier> input = new ConfigDocument<Identifier>(Identifier.class);
    input.setUniqueId(uid);
    input.setName("NewName");
    input.setValue(null); // name change only

    ConfigDocument<Identifier> updated = _cfgMaster.update(input);
    assertEquals(false, base.getUniqueId().equals(updated.getUniqueId()));
    assertEquals("NewName", updated.getName()); // name changed
    assertEquals(base.getValue(), updated.getValue()); // value unchanged

    ConfigDocument<Identifier> old = _cfgMaster.get(uid, Identifier.class);
    assertEquals(base.getUniqueId(), old.getUniqueId());
    assertEquals(now, old.getVersionToInstant()); // old version ended
    assertEquals(base.getName(), old.getName());
    assertEquals(base.getValue(), old.getValue());
  }
  @Test
  public void test_update_getUpdateGet() {
    Instant now = Instant.now(_cfgMaster.getTimeSource());

    UniqueIdentifier uid = UniqueIdentifier.of("DbCfg", "101", "0");
    ConfigDocument<Identifier> base = _cfgMaster.get(uid, Identifier.class);
    ConfigDocument<Identifier> input = new ConfigDocument<Identifier>(Identifier.class);
    input.setUniqueId(uid);
    input.setName("NewName");
    input.setValue(Identifier.of("A", "B"));

    ConfigDocument<Identifier> updated = _cfgMaster.update(input);
    assertEquals(false, base.getUniqueId().equals(updated.getUniqueId()));
    assertEquals(now, updated.getVersionFromInstant());
    assertEquals(null, updated.getVersionToInstant());
    assertEquals(now, updated.getCorrectionFromInstant());
    assertEquals(null, updated.getCorrectionToInstant());
    assertEquals("NewName", updated.getName());
    assertEquals(Identifier.of("A", "B"), updated.getValue());

    ConfigDocument<Identifier> old = _cfgMaster.get(uid, Identifier.class);
    assertEquals(base.getUniqueId(), old.getUniqueId());
    assertEquals(base.getVersionFromInstant(), old.getVersionFromInstant());
    assertEquals(now, old.getVersionToInstant()); // old version ended
    assertEquals(base.getCorrectionFromInstant(), old.getCorrectionFromInstant());
    assertEquals(base.getCorrectionToInstant(), old.getCorrectionToInstant());
    assertEquals(base.getName(), old.getName());
    assertEquals(base.getValue(), old.getValue());

    ConfigHistoryRequest<Identifier> search =
        new ConfigHistoryRequest<Identifier>(base.getUniqueId(), null, now);
    search.setType(Identifier.class);

    ConfigHistoryResult<Identifier> searchResult = _cfgMaster.history(search);
    assertEquals(2, searchResult.getDocuments().size());
  }
Ejemplo n.º 11
0
 public static URI uriClient(URI clientsBaseUri, UniqueIdentifier viewClientId) {
   return UriBuilder.fromUri(clientsBaseUri).segment(viewClientId.toString()).build();
 }
Ejemplo n.º 12
0
 // -------------------------------------------------------------------------
 @Path(PATH_PROCESSES + "/{viewProcessId}")
 public DataViewProcessResource getViewProcess(@PathParam("viewProcessId") String viewProcessId) {
   ViewProcess view = _viewProcessor.getViewProcess(UniqueIdentifier.parse(viewProcessId));
   return new DataViewProcessResource(view);
 }
Ejemplo n.º 13
0
 /**
  * Gets the best available batch id.
  *
  * @param overrideId the override id, null derives the result from the data
  * @return the id, may be null
  */
 public String getBestBatchUriId(final UniqueIdentifier overrideId) {
   if (overrideId != null) {
     return overrideId.toLatest().toString();
   }
   return getBatch() != null ? getBatch().getUniqueId().toLatest().toString() : getUriBatchId();
 }