Skip to content

Commit 44f57ee

Browse files
committed
upgrade exercises for TB 0.17.
1 parent 4bfb6a2 commit 44f57ee

11 files changed

+39
-55
lines changed

exercises/010_batch_limits.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@ source ./tools/tb_function.sh
77
# We said that everything in TigerBeetle is batched for efficiency and performance
88
# -- so let's take advantage of that!
99

10-
# Let's go crazy here and create 8189 accounts in a single request!
11-
# Why 8189? That's the maximum number we can send in a request.
10+
# The maximum number of events we can send in a single request is 8189.
11+
# Let's create 8189 accounts across two batches:
1212
create_account_batch="create_accounts "
13-
for ((i=0; i<8189; i++)); do
13+
for ((i=0; i<4000; i++)); do
1414
create_account_batch+="id=$((100000 + i)) code=10 ledger=100, "
1515
done
16+
tb "${create_account_batch%, };"
1617

17-
# Create the accounts (removing the trailing comma and space)
18+
create_account_batch="create_accounts "
19+
for ((i=4000; i<8189; i++)); do
20+
create_account_batch+="id=$((100000 + i)) code=10 ledger=100, "
21+
done
1822
tb "${create_account_batch%, };"
1923

2024
# Now let's do the same for transfers!
25+
# (We have to split them into batches because of the REPL's command-line size limit.)
2126

2227
create_transfer_batch="create_transfers "
23-
for ((i=0; i<8190; i++)); do
24-
create_transfer_batch+="id=$((1000 + i)) \
25-
debit_account_id=$((100000 + i)) \
26-
credit_account_id=$((100000 + (1 + i) % 8189)) \
27-
amount=1 \
28-
code=10 \
29-
ledger=100, "
28+
for ((i=0; i<1400; i++)); do
29+
create_transfer_batch+="id=$((1000 + i)) debit_account_id=$((100000 + i)) credit_account_id=$((100000 + (1 + i) % 8189)) amount=1 code=10 ledger=100, "
3030
done
31-
3231
tb "${create_transfer_batch%, };"
33-
# Uh oh! We might have gone a _little_ overboard and created one too many transfers!
3432

35-
# (If you're running TigerBeetle using a debug build, you'll see that this error
36-
# is triggered by an assertion failure in the client. TigerBeetle makes heavy use
37-
# of assertions to ensure that it operates as expected.)
33+
create_transfer_batch="create_transfers "
34+
for ((i=1400; i<2800; i++)); do
35+
create_transfer_batch+="id=$((1000 + i)) debit_account_id=$((100000 + i)) credit_account_id=$((100000 + (1 + i) % 8189)) amount=1 code=10 ledger=100, "
36+
done
37+
tb "${create_transfer_batch%, };"

exercises/021_linked_transfers.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ output=$(tb "create_transfers id=21000 debit_account_id=2100 credit_account_id=2
4040
id=21004 debit_account_id=2199 credit_account_id=2101 amount=100 ledger=200 code=10 flags=linked,
4141
id=21005 debit_account_id=2100 credit_account_id=2102 amount=100 ledger=200 code=10 flags=linked;")
4242

43-
if [[ $output =~ *"Failed to create transfer \(0|1|5\)"* ||
44-
$output != *"Failed to create transfer (2): tigerbeetle.CreateTransferResult.transfer_must_have_the_same_ledger_as_accounts."* ||
45-
$output != *"Failed to create transfer (3): tigerbeetle.CreateTransferResult.linked_event_failed."* ||
46-
$output != *"Failed to create transfer (4): tigerbeetle.CreateTransferResult.debit_account_not_found."* ]]; then
43+
if [[ $output != *"CreateTransferStatus.transfer_must_have_the_same_ledger_as_accounts"* ||
44+
$output != *"CreateTransferStatus.linked_event_failed"* ||
45+
( $output != *"CreateTransferStatus.debit_account_not_found"* && $output != *"CreateTransferStatus.id_already_failed"* ) ]]; then
4746

4847
echo "Uh oh! The transfers didn't have the expected results."
4948
exit 1

exercises/025_two_phase_transfers_timeout.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ echo "$output"
3030
# We can also check the account balances to see that only the second transfer was posted:
3131
tb "lookup_accounts id=2500, id=2501;"
3232

33-
if [[ $output != *"Failed to create transfer (0): tigerbeetle.CreateTransferResult.pending_transfer_expired."* ]]; then
33+
if [[ $output != *"CreateTransferStatus.pending_transfer_expired"* ]]; then
3434
echo "The first transfer should have timed out!"
3535
exit 1
3636
fi

exercises/026_two_phase_transfers_partial.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ output=$(tb "create_transfers id=26003 pending_id=26000 amount=500 flags=post_pe
2727
# Once it posts, you can check the account balances to see the results.
2828
tb "lookup_accounts id=2600, id=2601;"
2929

30-
if [[ $output == *"Failed to create transfer (2): tigerbeetle.CreateTransferResult.exceeds_pending_transfer_amount."* ]]; then
30+
if [[ $output == *"CreateTransferStatus.exceeds_pending_transfer_amount"* ]]; then
3131
echo "The third transfer should have been posted!"
3232
exit 1
3333
fi

exercises/027_balancing_transfers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tb "create_transfers id=27000 debit_account_id=2700 credit_account_id=2701 amoun
2626
# Notice that the amount is 0. TigerBeetle will calculate the account's net balance
2727
# (in this case the net credit balance because we're using a balancing_debit) and transfer it to the other account.
2828
# Also, we are ignoring the result of this command because if we run it a second time, it will return the
29-
# error `tigerbeetle.CreateTransferResult.exists_with_different_amount` because the amount will be 100 rather than 0.
29+
# error `tigerbeetle.CreateTransferStatus.exists_with_different_amount` because the amount will be 100 rather than 0.
3030

3131
# Can you zero out the balance of the other account?
3232
# (Remember, we don't want a `balancing_debit` in this case...)

patches/010_batch_limits.patch

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +0,0 @@
1-
diff --git a/exercises/010_batch_limits.sh b/exercises/010_batch_limits.sh
2-
index fa34cff..7f6a21c 100755
3-
--- a/exercises/010_batch_limits.sh
4-
+++ b/exercises/010_batch_limits.sh
5-
@@ -20,7 +20,7 @@ tb "${create_account_batch%, };"
6-
# Now let's do the same for transfers!
7-
8-
create_transfer_batch="create_transfers "
9-
-for ((i=0; i<8190; i++)); do
10-
+for ((i=0; i<8189; i++)); do
11-
create_transfer_batch+="id=$((1000 + i)) \
12-
debit_account_id=$((100000 + i)) \
13-
credit_account_id=$((100000 + (1 + i) % 8189)) \

patches/021_linked_transfers.patch

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
diff --git a/exercises/021_linked_transfers.sh b/exercises/021_linked_transfers.sh
2-
index 81589f7..4186bdf 100755
31
--- a/exercises/021_linked_transfers.sh
42
+++ b/exercises/021_linked_transfers.sh
5-
@@ -34,11 +34,11 @@ tb "create_accounts id=2100 code=10 ledger=200 flags=linked,
3+
@@ -34,11 +34,11 @@
64
# - The 6th transfer succeeds on its own
75

86
output=$(tb "create_transfers id=21000 debit_account_id=2100 credit_account_id=2102 amount=100 ledger=200 code=10 flags=linked,
@@ -16,5 +14,5 @@ index 81589f7..4186bdf 100755
1614
+ id=21004 debit_account_id=2199 credit_account_id=2101 amount=100 ledger=200 code=10,
1715
+ id=21005 debit_account_id=2100 credit_account_id=2102 amount=100 ledger=200 code=10;")
1816

19-
if [[ $output =~ *"Failed to create transfer \(0|1|5\)"* ||
20-
$output != *"Failed to create transfer (2): tigerbeetle.CreateTransferResult.transfer_must_have_the_same_ledger_as_accounts."* ||
17+
if [[ $output != *"CreateTransferStatus.transfer_must_have_the_same_ledger_as_accounts"* ||
18+
$output != *"CreateTransferStatus.linked_event_failed"* ||
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
diff --git a/exercises/025_two_phase_transfers_timeout.sh b/exercises/025_two_phase_transfers_timeout.sh
21
--- a/exercises/025_two_phase_transfers_timeout.sh
32
+++ b/exercises/025_two_phase_transfers_timeout.sh
43
@@ -21,8 +21,8 @@
5-
4+
65
# Now, we'll try to post both transfers.
76
# Can you fix this request to post both transfers?
87
-output=$(tb "create_transfers id=25002 pending_id=??? amount=200 flags=post_pending_transfer,
98
- id=25003 pending_id=25001 amount=100 flags=???;")
109
+output=$(tb "create_transfers id=25002 pending_id=25000 amount=200 flags=post_pending_transfer,
1110
+ id=25003 pending_id=25001 amount=100 flags=post_pending_transfer;")
1211
echo "$output"
13-
12+
1413
# Notice that the first transfer returns an error because the pending transfer already timed out.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
diff --git a/exercises/026_two_phase_transfers_partial.sh b/exercises/026_two_phase_transfers_partial.sh
21
--- a/exercises/026_two_phase_transfers_partial.sh
32
+++ b/exercises/026_two_phase_transfers_partial.sh
43
@@ -16,7 +16,7 @@
@@ -7,6 +6,6 @@ diff --git a/exercises/026_two_phase_transfers_partial.sh b/exercises/026_two_ph
76
id=26004 pending_id=26001 amount=200 flags=post_pending_transfer,
87
- id=26005 pending_id=26002 amount=200 flags=post_pending_transfer;")
98
+ id=26005 pending_id=26002 amount=100 flags=post_pending_transfer;")
10-
9+
1110
# Uh oh! That didn't work!
1211
# The first transfer is actually okay -- specifying the same amount as the pending transfer posts the full amount.

patches/027_balancing_transfers.patch

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
diff --git a/exercises/027_balancing_transfers.sh b/exercises/027_balancing_transfers.sh
2-
index f144f7e..3f1ebb8 100755
31
--- a/exercises/027_balancing_transfers.sh
42
+++ b/exercises/027_balancing_transfers.sh
5-
@@ -30,7 +30,7 @@ tb "create_transfers id=27000 debit_account_id=2700 credit_account_id=2701 amoun
3+
@@ -30,7 +30,7 @@
64

75
# Can you zero out the balance of the other account?
86
# (Remember, we don't want a `balancing_debit` in this case...)

0 commit comments

Comments
 (0)