Skip to content

Commit 4ab7b13

Browse files
committed
Only implement MaxItemsPerBatch
1 parent 4af7a1d commit 4ab7b13

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

lib/floe/workflow/item_batcher.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def max_items(context, state_input)
4242
end
4343

4444
def max_input_bytes(context, state_input)
45-
return max_input_bytes_per_batch if max_input_bytes_per_batch.present?
45+
return max_input_bytes_per_batch if max_input_bytes_per_batch
4646
return if max_input_bytes_per_batch_path.nil?
4747
result = max_input_bytes_per_batch_path.value(context, state_input)
4848
raise runtime_field_error!("MaxInputBytesPerBatchPath", result, "must be a positive integer") if result <= 0
@@ -51,8 +51,8 @@ def max_input_bytes(context, state_input)
5151
end
5252

5353
def validate!
54-
if [max_items_per_batch, max_input_bytes_per_batch, max_items_per_batch_path, max_input_bytes_per_batch_path].all?(&:nil?)
55-
parser_error!("must have one of \"MaxItemsPerBatch\", \"MaxItemsPerBatchPath\", \"MaxInputBytesPerBatch\", \"MaxInputBytesPerBatchPath\"")
54+
if [max_items_per_batch, max_items_per_batch_path].all?(&:nil?)
55+
parser_error!("must have one of \"MaxItemsPerBatch\", \"MaxItemsPerBatchPath\"")
5656
end
5757

5858
parser_error!("must not specify both \"MaxItemsPerBatch\" and \"MaxItemsPerBatchPath\"") if max_items_per_batch && max_items_per_batch_path

spec/workflow/item_batcher_spec.rb

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
expect { subject }
1010
.to raise_error(
1111
Floe::InvalidWorkflowError,
12-
"Map.ItemBatcher must have one of \"MaxItemsPerBatch\", \"MaxItemsPerBatchPath\", \"MaxInputBytesPerBatch\", \"MaxInputBytesPerBatchPath\""
12+
"Map.ItemBatcher must have one of \"MaxItemsPerBatch\", \"MaxItemsPerBatchPath\""
1313
)
1414
end
1515
end
@@ -50,17 +50,22 @@
5050
let(:payload) { {"MaxInputBytesPerBatch" => 1_024} }
5151

5252
it "returns an ItemBatcher" do
53+
pending "implement MaxInputBytesPerBatch"
5354
expect(subject).to be_kind_of(described_class)
5455
end
5556

5657
it "sets max_input_bytes_per_batch" do
58+
pending "implement MaxInputBytesPerBatch"
59+
5760
expect(subject.max_input_bytes_per_batch).to eq(payload["MaxInputBytesPerBatch"])
5861
end
5962

6063
context "that is an invalid value" do
6164
let(:payload) { {"MaxInputBytesPerBatch" => 0} }
6265

6366
it "raises an exception" do
67+
pending "implement MaxInputBytesPerBatch"
68+
6469
expect { subject }.to raise_error(Floe::InvalidWorkflowError, "Map.ItemBatcher field \"MaxInputBytesPerBatch\" value \"0\" must be a positive integer")
6570
end
6671
end
@@ -83,10 +88,14 @@
8388
let(:payload) { {"MaxInputBytesPerBatchPath" => "$.batchSize"} }
8489

8590
it "returns an ItemBatcher" do
91+
pending "implement MaxInputBytesPerBatchPath"
92+
8693
expect(subject).to be_kind_of(described_class)
8794
end
8895

8996
it "sets max_input_bytes_per_batch_path" do
97+
pending "implement MaxInputBytesPerBatchPath"
98+
9099
expect(subject.max_input_bytes_per_batch_path).to be_kind_of(Floe::Workflow::ReferencePath)
91100
expect(subject.max_input_bytes_per_batch_path).to have_attributes(:path => ["batchSize"])
92101
end
@@ -104,6 +113,8 @@
104113
let(:payload) { {"MaxInputBytesPerBatch" => 1_024, "MaxInputBytesPerBatchPath" => "$.batchSize"} }
105114

106115
it "raises an exception" do
116+
pending "implement MaxInputBytesPerBatchPath"
117+
107118
expect { subject }.to raise_error(Floe::InvalidWorkflowError, "Map.ItemBatcher must not specify both \"MaxInputBytesPerBatch\" and \"MaxInputBytesPerBatchPath\"")
108119
end
109120
end
@@ -139,6 +150,38 @@
139150
end
140151
end
141152

153+
context "with MaxInputBytesPerBatch" do
154+
let(:payload) { {"MaxInputBytesPerBatch" => 1_024} }
155+
156+
it "returns in batches of 2" do
157+
pending "support max bytes per batch"
158+
159+
expect(subject.value(context, input)).to eq([{"Items" => %w[a b]}, {"Items" => %w[c d]}, {"Items" => %w[e]}])
160+
end
161+
end
162+
163+
context "with MaxInputBytesPerBatchPath" do
164+
let(:payload) { {"MaxInputBytesPerBatchPath" => "$.bytesPerBatch"} }
165+
let(:state_input) { {"bytesPerBatch" => 1_024, "items" => input} }
166+
167+
it "returns in batches of 2" do
168+
pending "support max bytes per batch"
169+
170+
expect(subject.value(context, input, state_input)).to eq([{"Items" => %w[a b]}, {"Items" => %w[c d]}, {"Items" => %w[e]}])
171+
end
172+
173+
context "with an invalid value in input" do
174+
let(:state_input) { {"bytesPerBatch" => 0, "items" => input} }
175+
176+
it "raises an exception" do
177+
pending "support max bytes per batch"
178+
179+
expect { subject.value(context, input, state_input) }
180+
.to raise_error(Floe::ExecutionError, "Map.ItemBatcher field \"MaxInputBytesPerBatchPath\" value \"0\" must be a positive integer")
181+
end
182+
end
183+
end
184+
142185
context "with BatchInput" do
143186
let(:payload) { {"BatchInput" => {"foo.$" => "$.bar"}, "MaxItemsPerBatch" => 2} }
144187
let(:state_input) { {"bar" => "bar", "items" => input} }

0 commit comments

Comments
 (0)