mirror of https://github.com/apache/nifi.git
NIFI-11946 Support preserving created timestamp for Registry Flows
This closes #7604 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
af365414e9
commit
6bb2d62ffd
|
@ -339,11 +339,11 @@ public class RegistryService {
|
|||
if (versionedFlow.getBucketIdentifier() == null) {
|
||||
versionedFlow.setBucketIdentifier(bucketIdentifier);
|
||||
}
|
||||
|
||||
final long timestamp = System.currentTimeMillis();
|
||||
if (versionedFlow.getCreatedTimestamp() <= 0) {
|
||||
versionedFlow.setCreatedTimestamp(timestamp);
|
||||
}
|
||||
versionedFlow.setModifiedTimestamp(timestamp);
|
||||
|
||||
validate(versionedFlow, "Cannot create versioned flow");
|
||||
|
||||
// ensure the bucket exists
|
||||
|
@ -949,6 +949,7 @@ public class RegistryService {
|
|||
|
||||
/**
|
||||
* Group the differences in the comparison by component
|
||||
*
|
||||
* @param flowDifferences The differences to group together by component
|
||||
* @return A set of componentDifferenceGroups where each entry contains a set of differences specific to that group
|
||||
*/
|
||||
|
|
|
@ -57,6 +57,7 @@ import java.util.Set;
|
|||
import java.util.SortedSet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
@ -376,6 +377,67 @@ public class TestRegistryService {
|
|||
assertEquals(versionedFlow.getDescription(), createdFlow.getDescription());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateFlowWithCreatedTimestamp() {
|
||||
final BucketEntity existingBucket = new BucketEntity();
|
||||
existingBucket.setId("b1");
|
||||
existingBucket.setName("My Bucket");
|
||||
existingBucket.setDescription("This is my bucket");
|
||||
existingBucket.setCreated(new Date());
|
||||
|
||||
when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
|
||||
final long timestamp = System.currentTimeMillis()-1000; // 1 millisecond previous
|
||||
final VersionedFlow versionedFlow = new VersionedFlow();
|
||||
versionedFlow.setIdentifier("f1");
|
||||
versionedFlow.setName("My Flow");
|
||||
versionedFlow.setBucketIdentifier("b1");
|
||||
versionedFlow.setCreatedTimestamp(timestamp);
|
||||
versionedFlow.setModifiedTimestamp(timestamp);
|
||||
|
||||
doAnswer(createFlowAnswer()).when(metadataService).createFlow(any(FlowEntity.class));
|
||||
|
||||
final VersionedFlow createdFlow = registryService.createFlow(versionedFlow.getBucketIdentifier(), versionedFlow);
|
||||
assertNotNull(createdFlow);
|
||||
assertNotNull(createdFlow.getIdentifier());
|
||||
assertTrue(createdFlow.getCreatedTimestamp() > 0);
|
||||
assertTrue(createdFlow.getModifiedTimestamp() > 0);
|
||||
assertEquals(timestamp,createdFlow.getCreatedTimestamp());
|
||||
assertNotEquals(timestamp,createdFlow.getModifiedTimestamp());
|
||||
assertEquals(versionedFlow.getIdentifier(), createdFlow.getIdentifier());
|
||||
assertEquals(versionedFlow.getName(), createdFlow.getName());
|
||||
assertEquals(versionedFlow.getBucketIdentifier(), createdFlow.getBucketIdentifier());
|
||||
assertEquals(versionedFlow.getDescription(), createdFlow.getDescription());
|
||||
}
|
||||
@Test
|
||||
public void testCreateFlowWithPreserveSourcePropertiesTrueAndInvalidTimestamps() {
|
||||
final BucketEntity existingBucket = new BucketEntity();
|
||||
existingBucket.setId("b1");
|
||||
existingBucket.setName("My Bucket");
|
||||
existingBucket.setDescription("This is my bucket");
|
||||
existingBucket.setCreated(new Date());
|
||||
|
||||
when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
|
||||
final long timestamp = -1;
|
||||
final VersionedFlow versionedFlow = new VersionedFlow();
|
||||
versionedFlow.setIdentifier("f1");
|
||||
versionedFlow.setName("My Flow");
|
||||
versionedFlow.setBucketIdentifier("b1");
|
||||
versionedFlow.setCreatedTimestamp(timestamp);
|
||||
versionedFlow.setModifiedTimestamp(timestamp);
|
||||
|
||||
doAnswer(createFlowAnswer()).when(metadataService).createFlow(any(FlowEntity.class));
|
||||
|
||||
final VersionedFlow createdFlow = registryService.createFlow(versionedFlow.getBucketIdentifier(), versionedFlow);
|
||||
assertNotNull(createdFlow);
|
||||
assertNotNull(createdFlow.getIdentifier());
|
||||
assertTrue(createdFlow.getCreatedTimestamp() > 0);
|
||||
assertTrue(createdFlow.getModifiedTimestamp() > 0);
|
||||
assertEquals(versionedFlow.getIdentifier(), createdFlow.getIdentifier());
|
||||
assertEquals(versionedFlow.getName(), createdFlow.getName());
|
||||
assertEquals(versionedFlow.getBucketIdentifier(), createdFlow.getBucketIdentifier());
|
||||
assertEquals(versionedFlow.getDescription(), createdFlow.getDescription());
|
||||
}
|
||||
@Test
|
||||
public void testGetFlowDoesNotExist() {
|
||||
when(metadataService.getFlowById(any(String.class))).thenReturn(null);
|
||||
|
|
Loading…
Reference in New Issue