Skip to content

Commit

Permalink
pubsub: allow clearing of dead letter policies in subscriptions
Browse files Browse the repository at this point in the history
Fixes #1822

Change-Id: Icd6346ea1e8cf9fb9dd4ffb03750a7b68811a584
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/53170
Reviewed-by: kokoro <[email protected]>
Reviewed-by: Mahesh Gattani <[email protected]>
Reviewed-by: Cody Oss <[email protected]>
  • Loading branch information
hongalex committed Mar 12, 2020
1 parent 0b60a30 commit 6f2c791
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
52 changes: 52 additions & 0 deletions pubsub/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,3 +1219,55 @@ func TestIntegration_DeadLetterPolicy_DeliveryAttempt(t *testing.T) {
t.Fatalf("Streaming pull error: %v\n", err)
}
}

func TestIntegration_DeadLetterPolicy_ClearDeadLetter(t *testing.T) {
t.Parallel()
ctx := context.Background()
client := integrationTestClient(ctx, t)
defer client.Close()

topic, err := client.CreateTopic(ctx, topicIDs.New())
if err != nil {
t.Fatalf("CreateTopic error: %v", err)
}
defer topic.Delete(ctx)
defer topic.Stop()

deadLetterTopic, err := client.CreateTopic(ctx, topicIDs.New())
if err != nil {
t.Fatalf("CreateTopic error: %v", err)
}
defer deadLetterTopic.Delete(ctx)
defer deadLetterTopic.Stop()

cfg := SubscriptionConfig{
Topic: topic,
DeadLetterPolicy: &DeadLetterPolicy{
DeadLetterTopic: deadLetterTopic.String(),
},
}
var sub *Subscription
if sub, err = client.CreateSubscription(ctx, subIDs.New(), cfg); err != nil {
t.Fatalf("CreateSub error: %v", err)
}
defer sub.Delete(ctx)

sub.Update(ctx, SubscriptionConfigToUpdate{
DeadLetterPolicy: &DeadLetterPolicy{},
})

got, err := sub.Config(ctx)
if err != nil {
t.Fatal(err)
}
want := SubscriptionConfig{
Topic: topic,
AckDeadline: 10 * time.Second,
RetainAckedMessages: false,
RetentionDuration: defaultRetentionDuration,
ExpirationPolicy: defaultExpirationPolicy,
}
if diff := testutil.Diff(got, want); diff != "" {
t.Fatalf("SubsciptionConfig; got: - want: +\n%s", diff)
}
}
5 changes: 3 additions & 2 deletions pubsub/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ type DeadLetterPolicy struct {
}

func (dlp *DeadLetterPolicy) toProto() *pb.DeadLetterPolicy {
if dlp == nil {
if dlp == nil || dlp.DeadLetterTopic == "" {
return nil
}
return &pb.DeadLetterPolicy{
Expand Down Expand Up @@ -472,7 +472,8 @@ type SubscriptionConfigToUpdate struct {
// If non-zero, Expiration is changed.
ExpirationPolicy optional.Duration

// If non-nil, DeadLetterPolicy is changed.
// If non-nil, DeadLetterPolicy is changed. To remove dead lettering from
// a subscription, use the zero value for this struct.
//
// It is EXPERIMENTAL and a part of a closed alpha that may not be
// accessible to all users.
Expand Down

0 comments on commit 6f2c791

Please sign in to comment.