Skip to content

Commit

Permalink
feat: add script to create infinite courses
Browse files Browse the repository at this point in the history
  • Loading branch information
rgomezcasas committed Nov 13, 2023
1 parent b268158 commit 4d337d6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
33 changes: 33 additions & 0 deletions etc/scripts/create_infinite_courses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function create_course() {
eventId=$(uuidgen)
courseId=$(uuidgen)
courseName=$(shuf -n3 /usr/share/dict/words | xargs)
courseDuration=$((1 + RANDOM % 1000))

curl -X POST --location "http://localhost:8030/domain-events" \
-H "Content-Type: application/json" \
-d '{
"eventName": "course.created",
"eventRaw": {
"data": {
"id": "'"$eventId"'",
"type": "course.created",
"occurred_on": "2023-11-14 10:00:00",
"attributes": {
"id": "'"$courseId"'",
"name": "'"$courseName"'",
"duration": "'"$courseDuration"' days"
}
},
"meta": {
}
}
}'

echo "Created: $courseName"
}

while true; do
create_course &
sleep 0.001
done
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@

@Service
public final class CoursesCounterIncrementer {
private CoursesCounterRepository repository;
private UuidGenerator uuidGenerator;
private CoursesCounterRepository repository;
private UuidGenerator uuidGenerator;

public CoursesCounterIncrementer(CoursesCounterRepository repository, UuidGenerator uuidGenerator) {
this.repository = repository;
this.uuidGenerator = uuidGenerator;
}
public CoursesCounterIncrementer(CoursesCounterRepository repository, UuidGenerator uuidGenerator) {
this.repository = repository;
this.uuidGenerator = uuidGenerator;
}

public void increment(CourseId id) {
CoursesCounter counter = repository.search()
.orElseGet(() -> CoursesCounter.initialize(uuidGenerator.generate()));
public void increment(CourseId id) {
CoursesCounter counter = repository.search()
.orElseGet(() -> CoursesCounter.initialize(uuidGenerator.generate()));

if (!counter.hasIncremented(id)) {
counter.increment(id);
if (!counter.hasIncremented(id)) {
counter.increment(id);

repository.save(counter);
}
}
repository.save(counter);
}
}
}

0 comments on commit 4d337d6

Please sign in to comment.