/** * 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()); } }
private void applyAttributes(Collection<AttributeUpdate> updates, Map<UUID, Long> target) { updates.forEach(au -> target.put(au.getAttributeId(), 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 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 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); } }
@GuardedBy("this") @SneakyThrows(BadAttributeUpdateException.class) private void collectAttributeValue(AttributeUpdate update, Map<UUID, Long> values) { long newValue = update.getValue(); boolean hasValue = false; long previousValue = Attributes.NULL_ATTRIBUTE_VALUE; values.put(update.getAttributeId(), update.getValue());