e620833c9e
With this changeset, we provide an implementation for a transaction event API. The goal is to support the emission of events with transactions and sub-transactions, allowing a process post events that may be rolled back later due to an error in the entire process. When journaled, a consumer will be able to commit and rollback with the same behavior as the producer. Events are left to full definition by each component. We may require more structure in the future to ensure consistency but we need more use case before making decisions in that direction. Events may be organized by a topic. A topic defines a single stream of messages, that could be associated with a specific component. The topic defines a grouped stream that may be compacted as one. Only the contextual API is implemented here. After using, we will make a determination to see how useful this across the board. Signed-off-by: Stephen J Day <stephen.day@docker.com>
33 lines
624 B
Go
33 lines
624 B
Go
package events
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestBasicEvent(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
// simulate a layer pull with events
|
|
ctx, commit, _ := WithTx(ctx)
|
|
|
|
G(ctx).Post("pull ubuntu")
|
|
|
|
for layer := 0; layer < 4; layer++ {
|
|
// make a subtransaction for each layer
|
|
ctx, commit, _ := WithTx(ctx)
|
|
|
|
G(ctx).Post(fmt.Sprintf("fetch layer %v", layer))
|
|
|
|
ctx = WithTopic(ctx, "content")
|
|
// simulate sub-operations with a separate topic, on the content store
|
|
G(ctx).Post(fmt.Sprintf("received sha:256"))
|
|
|
|
G(ctx).Post(fmt.Sprintf("unpack layer %v", layer))
|
|
|
|
commit()
|
|
}
|
|
|
|
commit()
|
|
}
|