Skip to content

Commit

Permalink
all: rename of comments/variables storage -> broker
Browse files Browse the repository at this point in the history
  • Loading branch information
micvbang committed May 27, 2024
1 parent 5db01ec commit 81ce630
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestRecordClientGetRecordsHappyPath(t *testing.T) {
// TestRecordClientGetRecordsTopicDoesNotExist verifies that ErrNotFound is
// returned when attempting to read from a topic that does not exist.
func TestRecordClientGetRecordsTopicDoesNotExist(t *testing.T) {
srv := tester.HTTPServer(t, tester.HTTPStorageAutoCreateTopic(false))
srv := tester.HTTPServer(t, tester.HTTPBrokerAutoCreateTopic(false))
defer srv.Close()

client, err := seb.NewRecordClient(srv.Server.URL, tester.DefaultAPIKey)
Expand Down
6 changes: 3 additions & 3 deletions cmd/seb-api/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func Run() {

go sebcache.EvictionLoop(ctx, log.Name("cache eviction"), cache, flags.cacheMaxBytes, flags.cacheEvictionInterval)

blockingS3Storage, err := makeBlockingS3Broker(log, cache, flags.recordBatchSoftMaxBytes, flags.recordBatchBlockTime, flags.s3BucketName)
blockingS3Broker, err := makeBlockingS3Broker(log, cache, flags.recordBatchSoftMaxBytes, flags.recordBatchBlockTime, flags.s3BucketName)
if err != nil {
log.Fatalf("making blocking s3 storage: %s", err)
log.Fatalf("making blocking s3 broker: %s", err)
}

mux := http.NewServeMux()
httphandlers.RegisterRoutes(log, mux, blockingS3Storage, flags.httpAPIKey)
httphandlers.RegisterRoutes(log, mux, blockingS3Broker, flags.httpAPIKey)

errs := make(chan error, 8)

Expand Down
4 changes: 2 additions & 2 deletions internal/httphandlers/getrecords_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// TestGetRecordsExistence verifies that http.StatusNotFound is returned when
// either the topic name does not exist or the offset is out of bounds.
func TestGetRecordsExistence(t *testing.T) {
server := tester.HTTPServer(t, tester.HTTPStorageAutoCreateTopic(false))
server := tester.HTTPServer(t, tester.HTTPBrokerAutoCreateTopic(false))
defer server.Close()

const topicName = "topicName"
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestGetRecordsExistence(t *testing.T) {
// that must exist (topic name, offset).
func TestGetRecordsURLParameters(t *testing.T) {
const topicName = "topic-name"
server := tester.HTTPServer(t, tester.HTTPStorageAutoCreateTopic(false))
server := tester.HTTPServer(t, tester.HTTPBrokerAutoCreateTopic(false))
defer server.Close()

err := server.Broker.CreateTopic(topicName)
Expand Down
2 changes: 1 addition & 1 deletion internal/httphandlers/gettopic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestGetTopicNotFound(t *testing.T) {
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
server := tester.HTTPServer(t, tester.HTTPStorageAutoCreateTopic(test.autoCreateTopic))
server := tester.HTTPServer(t, tester.HTTPBrokerAutoCreateTopic(test.autoCreateTopic))
defer server.Close()

// Act
Expand Down
18 changes: 9 additions & 9 deletions internal/infrastructure/tester/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (s *HTTPTestServer) do(r *http.Request, addDefaultAuth bool) *http.Response
func HTTPServer(t *testing.T, OptFns ...func(*Opts)) *HTTPTestServer {
t.Helper()
opts := Opts{
APIKey: DefaultAPIKey,
StorageTopicAutoCreate: true,
APIKey: DefaultAPIKey,
BrokerTopicAutoCreate: true,
}
for _, optFn := range OptFns {
optFn(&opts)
Expand All @@ -79,7 +79,7 @@ func HTTPServer(t *testing.T, OptFns ...func(*Opts)) *HTTPTestServer {
log,
topicFactory,
sebbroker.WithNullBatcher(),
sebbroker.WithAutoCreateTopic(opts.StorageTopicAutoCreate),
sebbroker.WithAutoCreateTopic(opts.BrokerTopicAutoCreate),
)
opts.Dependencies = broker
}
Expand All @@ -98,9 +98,9 @@ func HTTPServer(t *testing.T, OptFns ...func(*Opts)) *HTTPTestServer {
}

type Opts struct {
APIKey string
StorageTopicAutoCreate bool
Dependencies httphandlers.Dependencies
APIKey string
BrokerTopicAutoCreate bool
Dependencies httphandlers.Dependencies
}

// HTTPAPIKey sets the apiKey for HTTPServer
Expand All @@ -110,10 +110,10 @@ func HTTPAPIKey(apiKey string) func(*Opts) {
}
}

// HTTPStorageAutoCreateTopic sets automatic topic creation for HTTPServer
func HTTPStorageAutoCreateTopic(autoCreate bool) func(*Opts) {
// HTTPBrokerAutoCreateTopic sets automatic topic creation for HTTPServer
func HTTPBrokerAutoCreateTopic(autoCreate bool) func(*Opts) {
return func(c *Opts) {
c.StorageTopicAutoCreate = autoCreate
c.BrokerTopicAutoCreate = autoCreate
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/sebbroker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Opts struct {
BatcherFactory batcherFactory
}

// New returns a Storage that utilizes topicFactory to store records.
// New returns a Broker that utilizes topicFactory to store records.
//
// It defaults to automatically create topics if they don't already exist.
// It defaults to batch records using NewBlockingBatcherFactory(1s, 10MB),
Expand Down Expand Up @@ -131,7 +131,7 @@ func (s *Broker) CreateTopic(topicName string) error {
}

// since topicBatchers is just a local cache of the topics that were
// instantiated during the lifetime of Storage, we don't yet know whether
// instantiated during the lifetime of Broker, we don't yet know whether
// the topic already exists or not. Checking the topic's nextOffset is a
// hacky way to attempt to do this.
if tb.topic.NextOffset() != 0 {
Expand Down
12 changes: 6 additions & 6 deletions internal/sebbroker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ func TestCreateTopicAlreadyExists(t *testing.T) {
})
}

// TestStorageMetadataHappyPath verifies that Metadata() returns the expected
// TestBrokerMetadataHappyPath verifies that Metadata() returns the expected
// data for a topic that exists.
func TestStorageMetadataHappyPath(t *testing.T) {
func TestBrokerMetadataHappyPath(t *testing.T) {
const autoCreate = true
tester.TestBroker(t, autoCreate, func(t *testing.T, s *sebbroker.Broker) {
const topicName = "topic-name"
Expand All @@ -334,10 +334,10 @@ func TestStorageMetadataHappyPath(t *testing.T) {
})
}

// TestStorageMetadataTopicNotFound verifies that ErrTopicNotFound is returned
// TestBrokerMetadataTopicNotFound verifies that ErrTopicNotFound is returned
// when attempting to read metadata from a topic that does not exist, when topic
// auto creation is turned off.
func TestStorageMetadataTopicNotFound(t *testing.T) {
func TestBrokerMetadataTopicNotFound(t *testing.T) {
tests := map[string]struct {
autoCreate bool
expectedErr error
Expand Down Expand Up @@ -406,9 +406,9 @@ func TestAddRecordHappyPath(t *testing.T) {
})
}

// TestStorageConcurrency exercises thread safety when doing reads and writes
// TestBrokerConcurrency exercises thread safety when doing reads and writes
// concurrently.
func TestStorageConcurrency(t *testing.T) {
func TestBrokerConcurrency(t *testing.T) {
const autoCreate = true
tester.TestBroker(t, autoCreate, func(t *testing.T, s *sebbroker.Broker) {
ctx := context.Background()
Expand Down

0 comments on commit 81ce630

Please sign in to comment.