/** * Accepts a collection of AttributeUpdates in the metadata. * * @param attributeUpdates The Attribute updates to accept. */ private void acceptAttributes(Collection<AttributeUpdate> attributeUpdates) { if (attributeUpdates == null) { return; } for (AttributeUpdate au : attributeUpdates) { this.attributeUpdates.put(au.getAttributeId(), au.getValue()); } }
/** * Creates a new instance of the BadAttributeUpdateException class. * * @param streamSegmentName The name of the StreamSegment. * @param attributeUpdate The AttributeUpdate that failed the check. * @param previousValueMissing If true, indicates that the previous value for this attempted Attribute Update was missing * and was likely the cause for the failed update. * @param errorMessage The Event Number that was given as part of the Operation. */ public BadAttributeUpdateException(String streamSegmentName, AttributeUpdate attributeUpdate, boolean previousValueMissing, String errorMessage) { super(streamSegmentName, getMessage(attributeUpdate, previousValueMissing, errorMessage)); this.previousValueMissing = previousValueMissing; this.attributeId = attributeUpdate == null ? null : attributeUpdate.getAttributeId(); }
/** * Collects the extended Attributes from the AttributeUpdates of the given operation. */ private Map<UUID, Long> getExtendedAttributes(AttributeUpdaterOperation operation) { Collection<AttributeUpdate> updates = operation.getAttributeUpdates(); if (updates == null) { return Collections.emptyMap(); } return updates.stream() .filter(au -> !Attributes.isCoreAttribute(au.getAttributeId())) .collect(Collectors.toMap(AttributeUpdate::getAttributeId, AttributeUpdate::getValue)); }
private void applyAttributes(Collection<AttributeUpdate> updates, Map<UUID, Long> target) { updates.forEach(au -> target.put(au.getAttributeId(), au.getValue())); }
boolean hasValue = false; long previousValue = Attributes.NULL_ATTRIBUTE_VALUE; if (this.attributeUpdates.containsKey(u.getAttributeId())) { hasValue = true; previousValue = this.attributeUpdates.get(u.getAttributeId()); } else if (this.baseAttributeValues.containsKey(u.getAttributeId())) { hasValue = true; previousValue = this.baseAttributeValues.get(u.getAttributeId());
private void assertSame(String message, Collection<AttributeUpdate> expected, Collection<AttributeUpdate> actual) { if (expected == null || expected.size() == 0) { Assert.assertTrue(message + " Not expecting attributes.", actual == null || actual.size() == 0); return; } else { Assert.assertNotNull(message + " Expected attributes, but none found.", actual); } Assert.assertEquals(message + " Unexpected number of attributes.", expected.size(), actual.size()); val expectedIndexed = expected.stream().collect(Collectors.toMap(AttributeUpdate::getAttributeId, AttributeUpdate::getValue)); for (AttributeUpdate au : actual) { Assert.assertTrue(message + " Found extra AttributeUpdate: " + au, expectedIndexed.containsKey(au.getAttributeId())); long expectedValue = expectedIndexed.get(au.getAttributeId()); Assert.assertEquals(message + " Unexpected value for AttributeUpdate: " + au, expectedValue, au.getValue()); } }
private void verifyAttributeUpdates(String stepName, ContainerMetadata containerMetadata, Collection<AttributeUpdate> attributeUpdates, Map<UUID, Long> expectedValues) { // Verify that the Attribute Updates have their expected values and that the updater has internalized the attribute updates. val transactionMetadata = containerMetadata.getStreamSegmentMetadata(SEGMENT_ID); val expectedTransactionAttributes = new HashMap<UUID, Long>(expectedValues); attributeUpdates.forEach(au -> expectedTransactionAttributes.put(au.getAttributeId(), au.getValue())); SegmentMetadataComparer.assertSameAttributes("Unexpected attributes in transaction metadata " + stepName + ".", expectedTransactionAttributes, transactionMetadata); for (AttributeUpdate au : attributeUpdates) { Assert.assertEquals("Unexpected updated value for AttributeUpdate[" + au.getUpdateType() + "] " + stepName, (long) expectedValues.get(au.getAttributeId()), au.getValue()); } }
private void writeAttributeUpdate00(RevisionDataOutput target, AttributeUpdate au) throws IOException { target.writeUUID(au.getAttributeId()); target.writeByte(au.getUpdateType().getTypeId()); target.writeLong(au.getValue()); target.writeLong(au.getComparisonValue()); }
private void writeAttributeUpdate00(RevisionDataOutput target, AttributeUpdate au) throws IOException { target.writeUUID(au.getAttributeId()); target.writeByte(au.getUpdateType().getTypeId()); target.writeLong(au.getValue()); target.writeLong(au.getComparisonValue()); }
private void recordAppend(long segmentId, int length, OperationMetadataUpdater updater, UpdateableContainerMetadata referenceMetadata) throws Exception { byte[] data = new byte[length]; val attributeUpdates = Arrays.asList( new AttributeUpdate(Attributes.CREATION_TIME, AttributeUpdateType.Replace, NEXT_ATTRIBUTE_VALUE.get()), new AttributeUpdate(Attributes.EVENT_COUNT, AttributeUpdateType.Accumulate, NEXT_ATTRIBUTE_VALUE.get())); val op = new StreamSegmentAppendOperation(segmentId, data, attributeUpdates); process(op, updater); if (referenceMetadata != null) { val rsm = referenceMetadata.getStreamSegmentMetadata(segmentId); rsm.setLength(rsm.getLength() + length); val attributes = new HashMap<UUID, Long>(); op.getAttributeUpdates().forEach(au -> attributes.put(au.getAttributeId(), au.getValue())); rsm.updateAttributes(attributes); } }
boolean hasValue = false; long previousValue = Attributes.NULL_ATTRIBUTE_VALUE; if (this.metadata.getAttributes().containsKey(update.getAttributeId())) { hasValue = true; previousValue = this.metadata.getAttributes().get(update.getAttributeId()); values.put(update.getAttributeId(), update.getValue());
Assert.assertFalse("Extended attribute was serialized.", checkpointedSm.getAttributes().containsKey(e.getAttributeId()));