protected function optimisticCheck(StreamId $streamId, string $expectedEtag, array $context): void
    {
        $slice = $this->getStreamSlice($streamId, null, 1, false, true, $context);

        if (!$slice->count()) {
            throw new OptimisticCheckFailed(
                sprintf(
                    'The DynamoDb table [%s] has no events in stream [%s].',
                    $this->getTableNameForRead($context),
                    $streamId
                )
            );
        }

        $event = $slice->getIterator()->current();

        // todo: review this etag strategy (need to make this more explicit/obvious)
        $eventId = (string)$event->get('event_id');
        if ($eventId === $expectedEtag || md5($eventId) === $expectedEtag) {
            return;
        }

        throw new OptimisticCheckFailed(
            sprintf(
                'The last event [%s:%s] in DynamoDb table [%s] from stream [%s] doesn\'t match expected etag [%s].',
                $eventId,
                md5($eventId),
                $this->getTableNameForRead($context),
                $streamId,
                $expectedEtag
            )
        );
    }