Skip to content

Commit

Permalink
tests/subscribe_to_stream_catching_up_should
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Oct 27, 2018
1 parent 50bc41d commit 04bf979
Show file tree
Hide file tree
Showing 10 changed files with 432 additions and 41 deletions.
4 changes: 2 additions & 2 deletions tests/Helper/TestEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private function __construct()
{
}

public static function new(?EventId $eventId = null, ?string $data = null, ?string $metadata = null): EventData
public static function newTestEvent(?EventId $eventId = null, ?string $data = null, ?string $metadata = null): EventData
{
if (null === $eventId) {
$eventId = EventId::generate();
Expand All @@ -38,7 +38,7 @@ public static function newAmount(int $amount): array
$events = [];

for ($i = 0; $i < $amount; $i++) {
$events[] = self::new();
$events[] = self::newTestEvent();
}

return $events;
Expand Down
52 changes: 26 additions & 26 deletions tests/append_to_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function should_create_stream_with_no_stream_exp_ver_on_first_write_if_do
yield $connection->connectAsync();

/** @var WriteResult $result */
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::new()]);
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);
$this->assertSame(0, $result->nextExpectedVersion());

/** @var StreamEventsSlice $slice */
Expand All @@ -134,7 +134,7 @@ public function should_create_stream_with_any_exp_ver_on_first_write_if_does_not
yield $connection->connectAsync();

/** @var WriteResult $result */
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::new()]);
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::newTestEvent()]);
$this->assertSame(0, $result->nextExpectedVersion());

/** @var StreamEventsSlice $slice */
Expand All @@ -158,7 +158,7 @@ public function multiple_idempotent_writes(): void

yield $connection->connectAsync();

$events = [TestEvent::new(), TestEvent::new(), TestEvent::new(), TestEvent::new()];
$events = [TestEvent::newTestEvent(), TestEvent::newTestEvent(), TestEvent::newTestEvent(), TestEvent::newTestEvent()];

/** @var WriteResult $result */
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, $events);
Expand All @@ -184,7 +184,7 @@ public function multiple_idempotent_writes_with_same_id_bug_case(): void

yield $connection->connectAsync();

$x = TestEvent::new();
$x = TestEvent::newTestEvent();
$events = [$x, $x, $x, $x, $x, $x];

/** @var WriteResult $result */
Expand All @@ -208,7 +208,7 @@ public function in_wtf_multiple_case_of_multiple_writes_expected_version_any_per

yield $connection->connectAsync();

$x = TestEvent::new();
$x = TestEvent::newTestEvent();
$events = [$x, $x, $x, $x, $x, $x];

/** @var WriteResult $result */
Expand Down Expand Up @@ -236,7 +236,7 @@ public function in_slightly_reasonable_multiple_case_of_multiple_writes_with_exp

yield $connection->connectAsync();

$x = TestEvent::new();
$x = TestEvent::newTestEvent();
$events = [$x, $x, $x, $x, $x, $x];

/** @var WriteResult $result */
Expand Down Expand Up @@ -268,7 +268,7 @@ public function should_fail_writing_with_correct_exp_ver_to_deleted_stream(): vo

try {
$this->expectException(StreamDeletedException::class);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, [TestEvent::newTestEvent()]);
} finally {
$connection->close();
}
Expand All @@ -289,7 +289,7 @@ public function should_return_log_position_when_writing(): void
yield $connection->connectAsync();

/** @var WriteResult $result */
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::new()]);
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
$this->assertGreaterThan(0, $result->logPosition()->preparePosition());
$this->assertGreaterThan(0, $result->logPosition()->commitPosition());

Expand Down Expand Up @@ -318,7 +318,7 @@ public function should_fail_writing_with_any_exp_ver_to_deleted_stream(): void

try {
$this->expectException(StreamDeletedException::class);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::newTestEvent()]);
} finally {
$connection->close();
}
Expand All @@ -342,7 +342,7 @@ public function should_fail_writing_with_invalid_exp_ver_to_deleted_stream(): vo

$this->expectException(StreamDeletedException::class);
try {
yield $connection->appendToStreamAsync($stream, 5, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, 5, [TestEvent::newTestEvent()]);
} finally {
$connection->close();
}
Expand All @@ -363,7 +363,7 @@ public function should_append_with_correct_exp_ver_to_existing_stream(): void

yield $connection->connectAsync();

yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);

$connection->close();
}));
Expand All @@ -383,10 +383,10 @@ public function should_append_with_any_exp_ver_to_existing_stream(): void
yield $connection->connectAsync();

/** @var WriteResult $result */
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::new()]);
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
$this->assertSame(0, $result->nextExpectedVersion());

$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::new()]);
$result = yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::newTestEvent()]);
$this->assertSame(1, $result->nextExpectedVersion());

$connection->close();
Expand All @@ -408,7 +408,7 @@ public function should_fail_appending_with_wrong_exp_ver_to_existing_stream(): v

try {
$this->expectException(WrongExpectedVersionException::class);
yield $connection->appendToStreamAsync($stream, 1, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, 1, [TestEvent::newTestEvent()]);
} finally {
$connection->close();
}
Expand All @@ -429,8 +429,8 @@ public function should_append_with_stream_exists_exp_ver_to_existing_stream(): v

yield $connection->connectAsync();

yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::newTestEvent()]);

$connection->close();
}));
Expand All @@ -451,10 +451,10 @@ public function should_append_with_stream_exists_exp_ver_to_stream_with_multiple
yield $connection->connectAsync();

for ($i = 0; $i < 5; $i++) {
yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::newTestEvent()]);
}

yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::newTestEvent()]);

$connection->close();
}));
Expand Down Expand Up @@ -482,7 +482,7 @@ public function should_append_with_stream_exists_exp_ver_if_metadata_stream_exis
)
);

yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::newTestEvent()]);

$connection->close();
}));
Expand All @@ -503,7 +503,7 @@ public function should_fail_appending_with_stream_exists_exp_ver_and_stream_does

try {
$this->expectException(WrongExpectedVersionException::class);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::newTestEvent()]);
} finally {
$connection->close();
}
Expand All @@ -527,7 +527,7 @@ public function should_fail_appending_with_stream_exists_exp_ver_to_hard_deleted

try {
$this->expectException(StreamDeletedException::class);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::newTestEvent()]);
} finally {
$connection->close();
}
Expand All @@ -551,7 +551,7 @@ public function should_fail_appending_with_stream_exists_exp_ver_to_soft_deleted

try {
$this->expectException(StreamDeletedException::class);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::STREAM_EXISTS, [TestEvent::newTestEvent()]);
} finally {
$connection->close();
}
Expand Down Expand Up @@ -596,7 +596,7 @@ public function returns_failure_status_when_conditionally_appending_with_version
yield $connection->connectAsync();

/** @var ConditionalWriteResult $result */
$result = yield $connection->conditionalAppendToStreamAsync($stream, 7, [TestEvent::new()]);
$result = yield $connection->conditionalAppendToStreamAsync($stream, 7, [TestEvent::newTestEvent()]);

$this->assertTrue($result->status()->equals(ConditionalWriteStatus::versionMismatch()));

Expand All @@ -618,7 +618,7 @@ public function returns_success_status_when_conditionally_appending_with_matchin
yield $connection->connectAsync();

/** @var ConditionalWriteResult $result */
$result = yield $connection->conditionalAppendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::new()]);
$result = yield $connection->conditionalAppendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::newTestEvent()]);

$this->assertTrue($result->status()->equals(ConditionalWriteStatus::succeeded()));
$this->assertNotNull($result->logPosition());
Expand All @@ -641,12 +641,12 @@ public function returns_failure_status_when_conditionally_appending_to_a_deleted

yield $connection->connectAsync();

yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::newTestEvent()]);

yield $connection->deleteStreamAsync($stream, ExpectedVersion::ANY, true);

/** @var ConditionalWriteResult $result */
$result = yield $connection->conditionalAppendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::new()]);
$result = yield $connection->conditionalAppendToStreamAsync($stream, ExpectedVersion::ANY, [TestEvent::newTestEvent()]);

$this->assertTrue($result->status()->equals(ConditionalWriteStatus::streamDeleted()));

Expand Down
8 changes: 4 additions & 4 deletions tests/appending_to_implicitly_created_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function sequence_0em1_0e0_non_idempotent(): void

yield $connection->connectAsync();

$events = [TestEvent::new()];
$events = [TestEvent::newTestEvent()];

$writer = new StreamWriter($connection, $stream, ExpectedVersion::NO_STREAM);

Expand Down Expand Up @@ -185,7 +185,7 @@ public function sequence_0em1_0any_idempotent(): void

yield $connection->connectAsync();

$events = [TestEvent::new()];
$events = [TestEvent::newTestEvent()];

$writer = new StreamWriter($connection, $stream, ExpectedVersion::NO_STREAM);

Expand Down Expand Up @@ -215,7 +215,7 @@ public function sequence_0em1_0em1_idempotent(): void

yield $connection->connectAsync();

$events = [TestEvent::new()];
$events = [TestEvent::newTestEvent()];

$writer = new StreamWriter($connection, $stream, ExpectedVersion::NO_STREAM);

Expand Down Expand Up @@ -386,7 +386,7 @@ public function sequence_S_0em1_1em1_E_S_0em1_1em1_2em1_E_idempotancy_fail(): vo

yield $connection->appendToStreamAsync($stream, ExpectedVersion::NO_STREAM, $events);

$events[] = TestEvent::new();
$events[] = TestEvent::newTestEvent();

$this->expectException(WrongExpectedVersionException::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function sequence_S_0em1_1em1_E_S_0em1_1em1_2em1_E_idempotancy_fail(): vo

$this->assertSame(1, $writeResult->nextExpectedVersion());

$events[] = TestEvent::new();
$events[] = TestEvent::newTestEvent();

/** @var OngoingTransaction $ongoingTransaction */
$ongoingTransaction = yield $writer->startTransaction(-1);
Expand Down
2 changes: 1 addition & 1 deletion tests/connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function should_close_connection_after_configured_amount_of_failed_reconn

$this->expectException(InvalidOperationException::class);

yield $connection->appendToStreamAsync('stream', ExpectedVersion::EMPTY_STREAM, [TestEvent::new()]);
yield $connection->appendToStreamAsync('stream', ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);
}));
}
}
2 changes: 1 addition & 1 deletion tests/deleting_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function should_return_log_position_when_writing(): void

yield $connection->connectAsync();

yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);

/** @var DeleteResult $delete */
$delete = yield $connection->deleteStreamAsync($stream, 0, true);
Expand Down
4 changes: 2 additions & 2 deletions tests/subscribe_should.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function be_able_to_subscribe_to_non_existing_stream_and_then_catch_new_e
$this->eventAppearedResolver($appeared)
);

yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::new()]);
yield $connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);

try {
$result = yield timeout($appeared->promise(), self::TIMEOUT);
Expand Down Expand Up @@ -97,7 +97,7 @@ public function allow_multiple_subscriptions_to_same_stream(): void
$this->eventAppearedResolver($appeared2)
);

$connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::new()]);
$connection->appendToStreamAsync($stream, ExpectedVersion::EMPTY_STREAM, [TestEvent::newTestEvent()]);

try {
$result = yield timeout($appeared1->promise(), self::TIMEOUT);
Expand Down
2 changes: 1 addition & 1 deletion tests/subscribe_to_all_catching_up_should.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function call_dropped_callback_when_an_error_occurs_while_processing_an_e
yield $store->appendToStreamAsync(
$stream,
ExpectedVersion::ANY,
[TestEvent::new()]
[TestEvent::newTestEvent()]
);

$dropped = new CountdownEvent(1);
Expand Down

0 comments on commit 04bf979

Please sign in to comment.