-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
128 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Basis\Nats\Message; | ||
|
||
class Nak extends Prototype | ||
{ | ||
public string $subject; | ||
public float $delay; | ||
|
||
public function render(): string | ||
{ | ||
$data = ['-NAK']; | ||
if (isset($this->delay) && $this->delay > 0) { | ||
$data[] = json_encode(['delay' => $this->delay * 10 ** 9]); | ||
} | ||
$payload = Payload::parse(implode(' ', $data))->render(); | ||
return "PUB $this->subject $payload"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Basis\Nats\Message; | ||
|
||
class Progress extends Prototype | ||
{ | ||
public string $subject; | ||
|
||
public function render(): string | ||
{ | ||
$payload = Payload::parse('+WPI')->render(); | ||
return "PUB $this->subject $payload"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Message; | ||
|
||
use Basis\Nats\Message\Ack; | ||
use Tests\TestCase; | ||
|
||
class AckTest extends TestCase | ||
{ | ||
public function testAck() | ||
{ | ||
$ack = new Ack([ | ||
'subject' => '$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0' | ||
]); | ||
|
||
$this->assertEquals("PUB \$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0 0\r\n", $ack->render()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Message; | ||
|
||
use Basis\Nats\Message\Nak; | ||
use Tests\TestCase; | ||
|
||
class NakTest extends TestCase | ||
{ | ||
public function testNak() | ||
{ | ||
$nak = new Nak([ | ||
'subject' => '$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0' | ||
]); | ||
|
||
$this->assertEquals("PUB \$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0 4\r\n-NAK", $nak->render()); | ||
} | ||
|
||
public function testNakDelay() | ||
{ | ||
$nak = new Nak([ | ||
'subject' => '$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0', | ||
'delay' => 10 | ||
]); | ||
|
||
$this->assertEquals("PUB \$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0 26\r\n-NAK {\"delay\":10000000000}", $nak->render()); | ||
} | ||
|
||
public function testNakFloatDelay() | ||
{ | ||
$nak = new Nak([ | ||
'subject' => '$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0', | ||
'delay' => 1.1 | ||
]); | ||
|
||
$this->assertEquals("PUB \$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0 25\r\n-NAK {\"delay\":1100000000}", $nak->render()); | ||
} | ||
public function testNakZeroDelay() | ||
{ | ||
$nak = new Nak([ | ||
'subject' => '$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0', | ||
'delay' => 0 | ||
]); | ||
|
||
$this->assertEquals("PUB \$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0 4\r\n-NAK", $nak->render()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Message; | ||
|
||
use Basis\Nats\Message\Progress; | ||
use Tests\TestCase; | ||
|
||
class ProgressTest extends TestCase | ||
{ | ||
public function testProgress() | ||
{ | ||
$progress = new Progress([ | ||
'subject' => '$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0' | ||
]); | ||
|
||
$this->assertEquals("PUB \$JS.ACK.stream.consumer.1.3.18.1719992702186105579.0 4\r\n+WPI", $progress->render()); | ||
} | ||
|
||
} |