mirror of
https://github.com/minio/minio.git
synced 2025-11-27 04:46:53 -05:00
Enhance the event store interface to support channeling (#7343)
- Avoids code duplication across the other targets. By having a centralized function call. - Reduce the room for race.
This commit is contained in:
committed by
Nitish Tiwari
parent
ddb0d646aa
commit
47ca411163
@@ -20,6 +20,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/minio/minio/pkg/event"
|
||||
@@ -55,7 +56,7 @@ func TestQueueStorePut(t *testing.T) {
|
||||
t.Fatal("Failed to tear down store ", err)
|
||||
}
|
||||
}()
|
||||
store, err := setUpStore(queueDir, 10000)
|
||||
store, err := setUpStore(queueDir, 100)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to create a queue store ", err)
|
||||
|
||||
@@ -67,8 +68,8 @@ func TestQueueStorePut(t *testing.T) {
|
||||
}
|
||||
}
|
||||
// Count the events.
|
||||
if len(store.ListAll()) != 100 {
|
||||
t.Fatalf("ListAll() Expected: 100, got %d", len(store.ListAll()))
|
||||
if len(store.ListN(-1)) != 100 {
|
||||
t.Fatalf("ListN() Expected: 100, got %d", len(store.ListN(-1)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +80,7 @@ func TestQueueStoreGet(t *testing.T) {
|
||||
t.Fatal("Failed to tear down store ", err)
|
||||
}
|
||||
}()
|
||||
store, err := setUpStore(queueDir, 10000)
|
||||
store, err := setUpStore(queueDir, 10)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to create a queue store ", err)
|
||||
}
|
||||
@@ -89,11 +90,11 @@ func TestQueueStoreGet(t *testing.T) {
|
||||
t.Fatal("Failed to put to queue store ", err)
|
||||
}
|
||||
}
|
||||
eventKeys := store.ListAll()
|
||||
eventKeys := store.ListN(-1)
|
||||
// Get 10 events.
|
||||
if len(eventKeys) == 10 {
|
||||
for _, key := range eventKeys {
|
||||
event, eErr := store.Get(key)
|
||||
event, eErr := store.Get(strings.TrimSuffix(key, eventExt))
|
||||
if eErr != nil {
|
||||
t.Fatal("Failed to Get the event from the queue store ", eErr)
|
||||
}
|
||||
@@ -102,7 +103,7 @@ func TestQueueStoreGet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
t.Fatalf("ListAll() Expected: 10, got %d", len(eventKeys))
|
||||
t.Fatalf("ListN() Expected: 10, got %d", len(eventKeys))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +114,7 @@ func TestQueueStoreDel(t *testing.T) {
|
||||
t.Fatal("Failed to tear down store ", err)
|
||||
}
|
||||
}()
|
||||
store, err := setUpStore(queueDir, 10000)
|
||||
store, err := setUpStore(queueDir, 20)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to create a queue store ", err)
|
||||
}
|
||||
@@ -123,18 +124,21 @@ func TestQueueStoreDel(t *testing.T) {
|
||||
t.Fatal("Failed to put to queue store ", err)
|
||||
}
|
||||
}
|
||||
eventKeys := store.ListAll()
|
||||
eventKeys := store.ListN(-1)
|
||||
// Remove all the events.
|
||||
if len(eventKeys) == 20 {
|
||||
for _, key := range eventKeys {
|
||||
store.Del(key)
|
||||
err := store.Del(strings.TrimSuffix(key, eventExt))
|
||||
if err != nil {
|
||||
t.Fatal("queue store Del failed with ", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
t.Fatalf("ListAll() Expected: 20, got %d", len(eventKeys))
|
||||
t.Fatalf("ListN() Expected: 20, got %d", len(eventKeys))
|
||||
}
|
||||
|
||||
if len(store.ListAll()) != 0 {
|
||||
t.Fatalf("ListAll() Expected: 0, got %d", len(store.ListAll()))
|
||||
if len(store.ListN(-1)) != 0 {
|
||||
t.Fatalf("ListN() Expected: 0, got %d", len(store.ListN(-1)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +161,32 @@ func TestQueueStoreLimit(t *testing.T) {
|
||||
}
|
||||
// Should not allow 6th Put.
|
||||
if err := store.Put(testEvent); err == nil {
|
||||
t.Fatalf("Expected to fail with %s, but passes", ErrLimitExceeded)
|
||||
t.Fatalf("Expected to fail with %s, but passes", errLimitExceeded)
|
||||
}
|
||||
}
|
||||
|
||||
// TestQueueStoreLimit - tests for store.LimitN.
|
||||
func TestQueueStoreListN(t *testing.T) {
|
||||
defer func() {
|
||||
if err := tearDownStore(); err != nil {
|
||||
t.Fatal("Failed to tear down store ", err)
|
||||
}
|
||||
}()
|
||||
store, err := setUpStore(queueDir, 10)
|
||||
if err != nil {
|
||||
t.Fatal("Failed to create a queue store ", err)
|
||||
}
|
||||
for i := 0; i < 10; i++ {
|
||||
if err := store.Put(testEvent); err != nil {
|
||||
t.Fatal("Failed to put to queue store ", err)
|
||||
}
|
||||
}
|
||||
// Should return only 5 event keys.
|
||||
if len(store.ListN(5)) != 5 {
|
||||
t.Fatalf("ListN(5) Expected: 5, got %d", len(store.ListN(5)))
|
||||
}
|
||||
// Should return all the event keys in the store.
|
||||
if len(store.ListN(-1)) != 10 {
|
||||
t.Fatalf("ListN(-1) Expected: 10, got %d", len(store.ListN(-1)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user