55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"tgs03-backend/context_handler"
|
|
"tgs03-backend/enrollment"
|
|
"tgs03-backend/poll"
|
|
"tgs03-backend/pool"
|
|
"tgs03-backend/worker"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("=== Tugas 1.1: Proses Sertifikasi ===")
|
|
results1 := worker.RunSertifikasi(50)
|
|
for _, r := range results1 {
|
|
fmt.Println(r)
|
|
}
|
|
|
|
fmt.Println("\n=== Tugas 1.2: Connection Pooling ===")
|
|
pm := pool.NewDBManager(5)
|
|
results2 := pm.RunQueries(20)
|
|
for _, r := range results2 {
|
|
fmt.Println(r)
|
|
}
|
|
|
|
fmt.Println("\n=== Tugas 1.3: Worker Pool untuk Live Poll ===")
|
|
results3 := poll.RunPollSimulation(5, 100)
|
|
for _, r := range results3 {
|
|
fmt.Println(r)
|
|
}
|
|
|
|
fmt.Println("\n=== Tugas 2.1 & 2.2: Context Timeout ===")
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*1)
|
|
defer cancel()
|
|
ctx = context_handler.WithUserID(ctx, "REQ-456")
|
|
res, err := context_handler.FetchRiwayatKursus(ctx)
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
} else {
|
|
fmt.Println("Result:", res)
|
|
}
|
|
|
|
fmt.Println("\n=== Tugas 2.3: Idempotent Enrollment ===")
|
|
enrollment.InitStore()
|
|
results5 := enrollment.RunConcurrentEnrollments("idem-key-sample", 5)
|
|
fmt.Println("Key:", results5["key"])
|
|
fmt.Println("Duration:", results5["duration"])
|
|
for _, r := range results5["results"].([]string) {
|
|
fmt.Println(r)
|
|
}
|
|
}
|