use of io.pravega.common.util.ImmutableDate in project pravega by pravega.
the class SegmentStatsRecorderTest method setup.
@Before
public void setup() {
AutoScaleProcessor processor = mock(AutoScaleProcessor.class);
StreamSegmentStore store = mock(StreamSegmentStore.class);
CompletableFuture<SegmentProperties> toBeReturned = CompletableFuture.completedFuture(new SegmentProperties() {
@Override
public String getName() {
return STREAM_SEGMENT_NAME;
}
@Override
public boolean isSealed() {
return false;
}
@Override
public boolean isDeleted() {
return false;
}
@Override
public ImmutableDate getLastModified() {
return null;
}
@Override
public long getStartOffset() {
return 0;
}
@Override
public long getLength() {
return 0;
}
@Override
public Map<UUID, Long> getAttributes() {
Map<UUID, Long> map = new HashMap<>();
map.put(Attributes.SCALE_POLICY_TYPE, 0L);
map.put(Attributes.SCALE_POLICY_RATE, 10L);
latch.complete(null);
return map;
}
});
when(store.getStreamSegmentInfo(STREAM_SEGMENT_NAME, false, Duration.ofMinutes(1))).thenReturn(toBeReturned);
statsRecorder = new SegmentStatsRecorderImpl(processor, store, 10000, 2, TimeUnit.SECONDS, executor, maintenanceExecutor);
}
use of io.pravega.common.util.ImmutableDate in project pravega by pravega.
the class ChunkedSegmentStorage method getStreamSegmentInfo.
@Override
public CompletableFuture<SegmentProperties> getStreamSegmentInfo(String streamSegmentName, Duration timeout) {
checkInitialized();
return executeParallel(() -> {
val traceId = LoggerHelpers.traceEnter(log, "getStreamSegmentInfo", streamSegmentName);
val timer = new Timer();
Preconditions.checkNotNull(streamSegmentName, "streamSegmentName");
log.debug("{} getStreamSegmentInfo - started segment={}.", logPrefix, streamSegmentName);
return tryWith(metadataStore.beginTransaction(true, streamSegmentName), txn -> txn.get(streamSegmentName).thenApplyAsync(storageMetadata -> {
SegmentMetadata segmentMetadata = (SegmentMetadata) storageMetadata;
checkSegmentExists(streamSegmentName, segmentMetadata);
segmentMetadata.checkInvariants();
val retValue = StreamSegmentInformation.builder().name(streamSegmentName).sealed(segmentMetadata.isSealed()).length(segmentMetadata.getLength()).startOffset(segmentMetadata.getStartOffset()).lastModified(new ImmutableDate(segmentMetadata.getLastModified())).build();
log.debug("{} getStreamSegmentInfo - finished segment={} latency={}.", logPrefix, streamSegmentName, timer.getElapsedMillis());
LoggerHelpers.traceLeave(log, "getStreamSegmentInfo", traceId, retValue);
return retValue;
}, executor), executor).handleAsync((v, ex) -> {
if (null != ex) {
log.debug("{} getStreamSegmentInfo - exception segment={}.", logPrefix, streamSegmentName, ex);
handleException(streamSegmentName, ex);
}
return v;
}, executor);
}, streamSegmentName);
}
use of io.pravega.common.util.ImmutableDate in project pravega by pravega.
the class FileSystemStorage method doGetStreamSegmentInfo.
protected SegmentProperties doGetStreamSegmentInfo(String streamSegmentName) throws IOException {
long traceId = LoggerHelpers.traceEnter(log, "getStreamSegmentInfo", streamSegmentName);
PosixFileAttributes attrs = Files.readAttributes(Paths.get(config.getRoot(), streamSegmentName), PosixFileAttributes.class);
StreamSegmentInformation information = StreamSegmentInformation.builder().name(streamSegmentName).length(attrs.size()).sealed(!(attrs.permissions().contains(OWNER_WRITE))).lastModified(new ImmutableDate(attrs.creationTime().toMillis())).build();
LoggerHelpers.traceLeave(log, "getStreamSegmentInfo", traceId, streamSegmentName);
return information;
}
use of io.pravega.common.util.ImmutableDate in project pravega by pravega.
the class DataRecoveryTest method testRepairLogEditOperationCreateSegmentProperties.
@Test
public void testRepairLogEditOperationCreateSegmentProperties() throws IOException {
// Setup command object.
STATE.set(new AdminCommandState());
Properties pravegaProperties = new Properties();
pravegaProperties.setProperty("pravegaservice.container.count", "1");
pravegaProperties.setProperty("pravegaservice.clusterName", "pravega0");
STATE.get().getConfigBuilder().include(pravegaProperties);
CommandArgs args = new CommandArgs(List.of("0"), STATE.get());
DurableDataLogRepairCommand command = Mockito.spy(new DurableDataLogRepairCommand(args));
// Create a SegmentProperties object via the command logic and verify that it is equal to the expected one.
long timestamp = System.currentTimeMillis();
Map<AttributeId, Long> attributes = new HashMap<>();
UUID uuid = UUID.randomUUID();
attributes.put(AttributeId.fromUUID(uuid), 10L);
Mockito.doReturn(true).doReturn(false).when(command).confirmContinue();
Mockito.doReturn(2L).doReturn(3L).doReturn(1L).doReturn(10L).doReturn(timestamp).when(command).getLongUserInput(Mockito.any());
Mockito.doReturn("test").doReturn(uuid.toString()).when(command).getStringUserInput(Mockito.any());
Mockito.doReturn(true).doReturn(true).doReturn(false).doReturn(false).when(command).getBooleanUserInput(Mockito.any());
SegmentProperties segmentProperties = StreamSegmentInformation.builder().name("test").startOffset(2).length(3).storageLength(1).sealed(true).deleted(false).sealedInStorage(true).deletedInStorage(false).attributes(attributes).lastModified(new ImmutableDate(timestamp)).build();
Assert.assertEquals(segmentProperties, command.createSegmentProperties());
// Induce exceptions during the process of creating attributes to check error handling.
segmentProperties = StreamSegmentInformation.builder().name("test").startOffset(2).length(3).storageLength(1).sealed(true).deleted(false).sealedInStorage(true).deletedInStorage(false).attributes(new HashMap<>()).lastModified(new ImmutableDate(timestamp)).build();
Mockito.doReturn(true).doReturn(false).when(command).confirmContinue();
Mockito.doReturn(true).doReturn(false).when(command).confirmContinue();
Mockito.doReturn(2L).doReturn(3L).doReturn(1L).doReturn(timestamp).when(command).getLongUserInput(Mockito.any());
Mockito.doReturn("test").doThrow(NumberFormatException.class).when(command).getStringUserInput(Mockito.any());
Mockito.doReturn(true).doReturn(true).doReturn(false).doReturn(false).when(command).getBooleanUserInput(Mockito.any());
Assert.assertEquals(segmentProperties, command.createSegmentProperties());
Mockito.doReturn(true).doReturn(false).when(command).confirmContinue();
Mockito.doReturn(true).doReturn(false).when(command).confirmContinue();
Mockito.doReturn(2L).doReturn(3L).doReturn(1L).doReturn(timestamp).when(command).getLongUserInput(Mockito.any());
Mockito.doReturn("test").doThrow(NullPointerException.class).when(command).getStringUserInput(Mockito.any());
Mockito.doReturn(true).doReturn(true).doReturn(false).doReturn(false).when(command).getBooleanUserInput(Mockito.any());
Assert.assertEquals(segmentProperties, command.createSegmentProperties());
}
use of io.pravega.common.util.ImmutableDate in project pravega by pravega.
the class StreamSegmentMetadataTests method testCopyFrom.
private void testCopyFrom(StreamSegmentMetadata baseMetadata) {
baseMetadata.setStorageLength(1233);
baseMetadata.updateAttributes(generateAttributes(new Random(0)));
baseMetadata.setLastModified(new ImmutableDate());
baseMetadata.markDeleted();
baseMetadata.markDeletedInStorage();
baseMetadata.markInactive();
baseMetadata.setLastUsed(1545895);
baseMetadata.markPinned();
// Normal metadata copy.
StreamSegmentMetadata newMetadata = new StreamSegmentMetadata(baseMetadata.getName(), baseMetadata.getId(), baseMetadata.getContainerId());
newMetadata.copyFrom(baseMetadata);
Assert.assertTrue("copyFrom copied the Active flag too.", newMetadata.isActive());
// Force the base metadata to update its core attributes with the correct type. Do this after the copyFrom call.
baseMetadata.refreshDerivedProperties();
SegmentMetadataComparer.assertEquals("Metadata copy:", baseMetadata, newMetadata);
Assert.assertEquals("Metadata copy: getLastUsed differs.", baseMetadata.getLastUsed(), newMetadata.getLastUsed());
// Verify we cannot copy from different StreamSegments.
AssertExtensions.assertThrows("copyFrom allowed copying from a metadata with a different Segment Name", () -> new StreamSegmentMetadata("foo", SEGMENT_ID, CONTAINER_ID).copyFrom(baseMetadata), ex -> ex instanceof IllegalArgumentException);
AssertExtensions.assertThrows("copyFrom allowed copying from a metadata with a different Segment Id", () -> new StreamSegmentMetadata(SEGMENT_NAME, -SEGMENT_ID, CONTAINER_ID).copyFrom(baseMetadata), ex -> ex instanceof IllegalArgumentException);
}
Aggregations