diff --git a/etc/scripts/create_infinite_courses.sh b/etc/scripts/create_infinite_courses.sh new file mode 100644 index 00000000..2467ee9a --- /dev/null +++ b/etc/scripts/create_infinite_courses.sh @@ -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 diff --git a/src/mooc/main/tv/codely/mooc/courses_counter/application/increment/CoursesCounterIncrementer.java b/src/mooc/main/tv/codely/mooc/courses_counter/application/increment/CoursesCounterIncrementer.java index c4433c07..2f80400d 100644 --- a/src/mooc/main/tv/codely/mooc/courses_counter/application/increment/CoursesCounterIncrementer.java +++ b/src/mooc/main/tv/codely/mooc/courses_counter/application/increment/CoursesCounterIncrementer.java @@ -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); + } + } }