Skip to content

Commit

Permalink
Merge pull request #4 from sotchenkov/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
sotchenkov authored Jun 20, 2024
2 parents 28dba7b + 4143fe0 commit 3abbf38
Show file tree
Hide file tree
Showing 24 changed files with 252 additions and 31 deletions.
Empty file modified Dockerfile
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified assets/limero_logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified assets/swag.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified cmd/limero/main.go
100644 → 100755
Empty file.
Empty file modified docs/docs.go
100644 → 100755
Empty file.
Empty file modified docs/swagger.json
100644 → 100755
Empty file.
Empty file modified docs/swagger.yaml
100644 → 100755
Empty file.
Empty file modified go.mod
100644 → 100755
Empty file.
Empty file modified go.sum
100644 → 100755
Empty file.
Empty file modified imgs/limero_logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified imgs/swag.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified internal/lib/logger/middleware.go
100644 → 100755
Empty file.
Empty file modified internal/lib/response/response.go
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion internal/queue/queue.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Message struct {
Value string `json:"value"`
Value map[string]interface{} `json:"value"`
}

// NewQueue returns a new queue with the given initial presize.
Expand Down
16 changes: 10 additions & 6 deletions internal/queue/queue_test.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package queue

import (
"reflect"
"testing"
)

Expand All @@ -13,16 +14,19 @@ func TestNewQueue(t *testing.T) {

func TestPushAndPop(t *testing.T) {
q := NewQueue(2, "testQueue")
msg1 := &Message{Value: "first"}
msg2 := &Message{Value: "second"}
msg1 := &Message{Value: map[string]interface{}{"message": "first"}}
msg2 := &Message{Value: map[string]interface{}{"message": "second"}}

q.Push(msg1)
q.Push(msg2)

if q.Pop().Value != "first" {
poppedMsg1 := q.Pop()
if !reflect.DeepEqual(poppedMsg1.Value, map[string]interface{}{"message": "first"}) {
t.Errorf("Pop did not return the first pushed message")
}
if q.Pop().Value != "second" {

poppedMsg2 := q.Pop()
if !reflect.DeepEqual(poppedMsg2.Value, map[string]interface{}{"message": "second"}) {
t.Errorf("Pop did not return the second pushed message")
}
}
Expand All @@ -33,15 +37,15 @@ func TestIsEmpty(t *testing.T) {
t.Errorf("IsEmpty should return true for a new queue")
}

q.Push(&Message{Value: "test"})
q.Push(&Message{Value: map[string]interface{}{"message": "test"}})
if q.IsEmpty() {
t.Errorf("IsEmpty should return false for a queue with messages")
}
}

func TestInfo(t *testing.T) {
q := NewQueue(10, "testQueue")
q.Push(&Message{Value: "test"})
q.Push(&Message{Value: map[string]interface{}{"message": "test"}})

info := q.Info()
if info.Name != "testQueue" || info.Presize != 10 || info.Size != 10 || info.Head != 0 || info.Tail != 1 || info.Count != 1 {
Expand Down
Empty file modified internal/server/handlers/msg.go
100644 → 100755
Empty file.
41 changes: 17 additions & 24 deletions internal/server/handlers/msg_test.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestPushMsgWithoutQueueName(t *testing.T) {
body := strings.NewReader(`{"value":"test message"}`)
body := strings.NewReader(`{"value":{"message":"test message"}}`)
req, err := http.NewRequest("POST", "/msg", body)
if err != nil {
t.Fatal(err)
Expand All @@ -24,7 +24,7 @@ func TestPushMsgWithoutQueueName(t *testing.T) {
}

func TestPushMsgToNonExistentQueue(t *testing.T) {
body := strings.NewReader(`{"value":"test message"}`)
body := strings.NewReader(`{"value":{"message":"test message"}}`)
req, err := http.NewRequest("POST", "/msg?qname=nonexistent", body)
if err != nil {
t.Fatal(err)
Expand All @@ -39,11 +39,9 @@ func TestPushMsgToNonExistentQueue(t *testing.T) {

func TestPushMsgWithUnsupportedType(t *testing.T) {
req, err := http.NewRequest("PUT", "/queue?name=testQueue&size=10", nil)

if err != nil {
t.Fatal(err)
}

rr := httptest.NewRecorder()
createQueue(rr, req)

Expand All @@ -52,7 +50,6 @@ func TestPushMsgWithUnsupportedType(t *testing.T) {
if err != nil {
t.Fatal(err)
}

req.Header.Set("Content-Type", "text/plain")
rr = httptest.NewRecorder()
PushMsg(rr, req)
Expand All @@ -64,11 +61,9 @@ func TestPushMsgWithUnsupportedType(t *testing.T) {

func TestPushMsgWithEmptyBody(t *testing.T) {
req, err := http.NewRequest("PUT", "/queue?name=testQueue&size=10", nil)

if err != nil {
t.Fatal(err)
}

rr := httptest.NewRecorder()
createQueue(rr, req)

Expand All @@ -87,15 +82,13 @@ func TestPushMsgWithEmptyBody(t *testing.T) {

func TestSuccessfulMsgPush(t *testing.T) {
req, err := http.NewRequest("PUT", "/queue?name=testQueue&size=10", nil)

if err != nil {
t.Fatal(err)
}

rr := httptest.NewRecorder()
createQueue(rr, req)

body := strings.NewReader(`{"value": "test"}`)
body := strings.NewReader(`{"value": {"message": "test"}}`)
req, err = http.NewRequest("POST", "/msg?qname=testQueue", body)
if err != nil {
t.Fatal(err)
Expand All @@ -116,7 +109,7 @@ func BenchmarkPushMsgQueueSize1(b *testing.B) {

// Run the benchmark
for i := 0; i < b.N; i++ {
body := strings.NewReader(`{"value":"message"}`)
body := strings.NewReader(`{"value":{"message":"message"}}`)
req, _ := http.NewRequest("POST", "/msg?qname="+queueName, body)
rr := httptest.NewRecorder()
PushMsg(rr, req)
Expand All @@ -131,22 +124,22 @@ func BenchmarkPushMsgQueueSize100(b *testing.B) {

// Run the benchmark
for i := 0; i < b.N; i++ {
body := strings.NewReader(`{"value":"message"}`)
body := strings.NewReader(`{"value":{"message":"message"}}`)
req, _ := http.NewRequest("POST", "/msg?qname="+queueName, body)
rr := httptest.NewRecorder()
PushMsg(rr, req)
}
}

func BenchmarkPushMsgQueueSize1000(b *testing.B) {
func BenchmarkPushMsgQueueSize100000(b *testing.B) {
// Setup
queueName := "testQueueSize1000"
queues[queueName] = queue.NewQueue(1000, queueName)
queueName := "testQueueSize100000"
queues[queueName] = queue.NewQueue(100000, queueName)
defer delete(queues, queueName)

// Run the benchmark
for i := 0; i < b.N; i++ {
body := strings.NewReader(`{"value":"message"}`)
body := strings.NewReader(`{"value":{"message":"message"}}`)
req, _ := http.NewRequest("POST", "/msg?qname="+queueName, body)
rr := httptest.NewRecorder()
PushMsg(rr, req)
Expand Down Expand Up @@ -208,7 +201,7 @@ func TestSuccessfulMsgPop(t *testing.T) {
rr := httptest.NewRecorder()
createQueue(rr, req)

body := strings.NewReader(`{"value": "test"}`)
body := strings.NewReader(`{"value": {"message": "test"}}`)
req, err = http.NewRequest("POST", "/msg?qname=testQueue", body)
if err != nil {
t.Fatal(err)
Expand All @@ -233,7 +226,7 @@ func BenchmarkPopMsgQueueSize1(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
queueName := "testQueueSize1"
localQueue := queue.NewQueue(1, queueName)
localQueue.Push(&queue.Message{Value: "message"})
localQueue.Push(&queue.Message{Value: map[string]interface{}{"message": "message"}})

for pb.Next() {
req, err := http.NewRequest("GET", "/msg?qname="+queueName, nil)
Expand All @@ -249,9 +242,9 @@ func BenchmarkPopMsgQueueSize1(b *testing.B) {

func BenchmarkPopMsgQueueSize100(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
queueName := "testQueueSize1"
queueName := "testQueueSize100"
localQueue := queue.NewQueue(100, queueName)
localQueue.Push(&queue.Message{Value: "message"})
localQueue.Push(&queue.Message{Value: map[string]interface{}{"message": "message"}})

for pb.Next() {
req, err := http.NewRequest("GET", "/msg?qname="+queueName, nil)
Expand All @@ -265,11 +258,11 @@ func BenchmarkPopMsgQueueSize100(b *testing.B) {
})
}

func BenchmarkPopMsgQueueSize10000(b *testing.B) {
func BenchmarkPopMsgQueueSize100000(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
queueName := "testQueueSize10000"
localQueue := queue.NewQueue(1000, queueName)
localQueue.Push(&queue.Message{Value: "message"})
queueName := "testQueueSize100000"
localQueue := queue.NewQueue(100000, queueName)
localQueue.Push(&queue.Message{Value: map[string]interface{}{"message": "message"}})

for pb.Next() {
req, err := http.NewRequest("GET", "/msg?qname="+queueName, nil)
Expand Down
Empty file modified internal/server/handlers/queue.go
100644 → 100755
Empty file.
Empty file modified internal/server/handlers/queue_test.go
100644 → 100755
Empty file.
Empty file modified internal/server/handlers/root.go
100644 → 100755
Empty file.
9 changes: 9 additions & 0 deletions internal/server/server.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"log"
"net/http"

"net/http/pprof"

_ "github.com/sotchenkov/limero/docs"
"github.com/sotchenkov/limero/internal/lib/logger"
"github.com/sotchenkov/limero/internal/server/handlers"
Expand All @@ -18,6 +20,13 @@ func Serv(zlog *zap.Logger) {
httpSwagger.URL("https://localhost:7920/swagger/doc.json"),
))

// Регистрация pprof-обработчиков
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)

mux.HandleFunc("/", handlers.Root)
mux.HandleFunc("/ping", handlers.Ping)
mux.HandleFunc("/queue", handlers.ActionOnQueueHandlers)
Expand Down
Loading

0 comments on commit 3abbf38

Please sign in to comment.