Skip to content

Conversation

@Markliniubility
Copy link

Description

This PR adds continuation token support to SyncPoller for Azure Resource Manager (ARM) Long-Running Operations (LROs), enabling LROs to be resumed across process restarts or transferred between processes.

What's Changed

This implementation allows users to:

  1. Serialize the state of an ongoing ARM LRO to a continuation token (Base64-encoded JSON string)
  2. Store the token (e.g., in a database, file system, or cache)
  3. Resume the LRO from the token in a different process or after a restart
  4. Continue polling until the operation completes

Implementation Details

Core Infrastructure (azure-core-management)

  • PollingState: Added toContinuationToken() and fromContinuationToken() methods to serialize/deserialize polling state
  • ArmLroSyncPoller: New wrapper class that implements continuation token support for ARM LRO pollers
  • SyncPollerFactory: Added resumeFromToken() static method to reconstruct pollers from continuation tokens

Interface Extension (azure-core)

  • SyncPoller: Added serializeContinuationToken() method with default implementation that throws UnsupportedOperationException
    • Only ARM LRO pollers created via SyncPollerFactory support this feature

Testing

  • 9 unit tests in PollingStateContinuationTokenTest covering token serialization/deserialization, error cases, and edge cases
  • 3 integration tests in SyncPollerContinuationTokenTest covering end-to-end resume workflow with mocked HTTP responses
  • All 12 tests passing

Usage Example

// Start a long-running operation
SyncPoller<PollResult<ServerInner>, ServerInner> poller = 
    SyncPollerFactory.create(
        serializerAdapter,
        httpPipeline,
        ServerInner.class,
        ServerInner.class,
        Duration.ofSeconds(30),
        () -> client.createServerWithResponse(resourceGroup, serverName, parameters),
        Context.NONE);

// Poll a few times
poller.poll();

// Get continuation token and store it
String token = poller.serializeContinuationToken();
saveTokenToDatabase(token);

// === Process restart or different process ===

// Load token and resume polling
String loadedToken = loadTokenFromDatabase();
SyncPoller<PollResult<ServerInner>, ServerInner> resumedPoller = 
    SyncPollerFactory.resumeFromToken(
        loadedToken,
        serializerAdapter,
        httpPipeline,
        ServerInner.class,
        ServerInner.class,
        Duration.ofSeconds(30),
        Context.NONE);

// Continue polling until completion
ServerInner result = resumedPoller.getFinalResult();

Files Changed

Core Implementation (4 files):

  • PollingState.java - Added token serialization methods
  • ArmLroSyncPoller.java - New wrapper for ARM LRO pollers (119 lines)
  • SyncPollerFactory.java - Added resume functionality
  • SyncPoller.java - Added interface method

Tests (3 files):

  • PollingStateContinuationTokenTest.java - Unit tests (195 lines)
  • SyncPollerContinuationTokenTest.java - Integration tests (231 lines)
  • FooWithProvisioningState.java - Test model updates

Documentation (2 files):

  • azure-core-management/CHANGELOG.md
  • azure-core/CHANGELOG.md

Total: 9 files changed, 803 insertions(+), 5 deletions(-)

Design Decisions

  1. Token Format: Internal JSON format, Base64-encoded, versioned (subject to change between SDK versions)
  2. Security: Token contains operation URLs - users should store tokens securely
  3. Scope: Implemented for ARM LROs in azure-core-management; can be extended to data-plane LROs in future
  4. Backward Compatibility: Default implementation throws UnsupportedOperationException to maintain compatibility

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes] - New methods only, with default implementations
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.
    • 9 unit tests for token serialization/deserialization
    • 3 integration tests for end-to-end resume workflow
    • All 12 tests passing

@github-actions github-actions bot added Azure.Core azure-core Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Nov 12, 2025
@github-actions
Copy link
Contributor

Thank you for your contribution @Markliniubility! We will review the pull request and get back to you soon.

@Markliniubility Markliniubility changed the title Add continuation token support for SyncPoller ARM LROs WIP: Add continuation token support for SyncPoller ARM LROs Nov 12, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 12, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

com.azure:azure-core-management
com.azure:azure-core

@Markliniubility Markliniubility force-pushed the feature/syncpoller-continuation-tokens branch from 0dd9112 to bd3fbc2 Compare November 12, 2025 02:23
@Markliniubility Markliniubility marked this pull request as draft November 12, 2025 02:24
- Add PollingState.toContinuationToken() and fromContinuationToken() methods
- Add SyncPoller.serializeContinuationToken() interface method
- Implement ArmLroSyncPoller wrapper with continuation token support
- Add SyncPollerFactory.resumeFromToken() to reconstruct pollers from tokens
- Add comprehensive unit and integration tests (12 tests, all passing)
- Update CHANGELOGs for azure-core and azure-core-management

This enables ARM Long-Running Operations to be resumed across process
restarts by serializing the poller state to a Base64-encoded token.
@Markliniubility Markliniubility force-pushed the feature/syncpoller-continuation-tokens branch from bd3fbc2 to 404f17d Compare November 12, 2025 02:43
@Markliniubility
Copy link
Author

@microsoft-github-policy-service agree

@Markliniubility Markliniubility marked this pull request as ready for review November 12, 2025 20:58
@Markliniubility Markliniubility changed the title WIP: Add continuation token support for SyncPoller ARM LROs Add continuation token support for SyncPoller ARM LROs Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Core azure-core Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants