@Test void testInitializeSegmentThrowsUnableToInitializeTokenExceptionForDuplicateKey() { GlobalSequenceTrackingToken testToken = new GlobalSequenceTrackingToken(100); tokenStore.initializeSegment(testToken, testProcessorName, testSegment); assertThrows( UnableToInitializeTokenException.class, () -> tokenStore.initializeSegment(testToken, testProcessorName, testSegment) ); }
@Override public void initializeSegment(TrackingToken token, String processorName, int segment) throws UnableToInitializeTokenException { try { AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(token, serializer, contentType, processorName, segment); mongoTemplate.trackingTokensCollection() .insertOne(tokenEntryToDocument(tokenEntry)); } catch (MongoWriteException exception) { if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) { throw new UnableToInitializeTokenException( format("Unable to initialize token '%s[%s]'", processorName, segment) ); } } }
MongoTokenStore implements TokenStore { @Override public void initializeSegment(TrackingToken token, String processorName, int segment) throws UnableToInitializeTokenException { try { AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(token, serializer, contentType, processorName, segment); mongoTemplate.trackingTokensCollection() .insertOne(tokenEntryToDocument(tokenEntry)); } catch (MongoWriteException exception) { if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) { throw new UnableToInitializeTokenException( format("Unable to initialize token '%s[%s]'", processorName, segment) ); } } } }
MongoTokenStore implements TokenStore { @Override public void initializeSegment(TrackingToken token, String processorName, int segment) throws UnableToInitializeTokenException { try { AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(token, serializer, contentType, processorName, segment); mongoTemplate.trackingTokensCollection() .insertOne(tokenEntryToDocument(tokenEntry)); } catch (MongoWriteException exception) { if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) { throw new UnableToInitializeTokenException( format("Unable to initialize token '%s[%s]'", processorName, segment) ); } } } protected  MongoTokenStore(Builder builder); }
MongoTokenStore implements TokenStore { @Override public void initializeSegment(TrackingToken token, String processorName, int segment) throws UnableToInitializeTokenException { try { AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(token, serializer, contentType, processorName, segment); mongoTemplate.trackingTokensCollection() .insertOne(tokenEntryToDocument(tokenEntry)); } catch (MongoWriteException exception) { if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) { throw new UnableToInitializeTokenException( format("Unable to initialize token '%s[%s]'", processorName, segment) ); } } } protected  MongoTokenStore(Builder builder); static Builder builder(); @Override void storeToken(TrackingToken token, String processorName, int segment); @Override void initializeTokenSegments(String processorName, int segmentCount); @Override void initializeTokenSegments(String processorName,
                                        int segmentCount,
                                        TrackingToken initialToken); @Override TrackingToken fetchToken(String processorName, int segment); @Override void extendClaim(String processorName, int segment); @Override void releaseClaim(String processorName, int segment); @Override void initializeSegment(TrackingToken token,
                                  String processorName,
                                  int segment); @Override void deleteToken(String processorName, int segment); @Override boolean requiresExplicitSegmentInitialization(); @Override int[] fetchSegments(String processorName); @Deprecated void ensureIndexes(); }
MongoTokenStore implements TokenStore { @Override public void initializeSegment(TrackingToken token, String processorName, int segment) throws UnableToInitializeTokenException { try { AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(token, serializer, contentType, processorName, segment); mongoTemplate.trackingTokensCollection() .insertOne(tokenEntryToDocument(tokenEntry)); } catch (MongoWriteException exception) { if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) { throw new UnableToInitializeTokenException( format("Unable to initialize token '%s[%s]'", processorName, segment) ); } } } protected  MongoTokenStore(Builder builder); static Builder builder(); @Override void storeToken(TrackingToken token, String processorName, int segment); @Override void initializeTokenSegments(String processorName, int segmentCount); @Override void initializeTokenSegments(String processorName,
                                        int segmentCount,
                                        TrackingToken initialToken); @Override TrackingToken fetchToken(String processorName, int segment); @Override void extendClaim(String processorName, int segment); @Override void releaseClaim(String processorName, int segment); @Override void initializeSegment(TrackingToken token,
                                  String processorName,
                                  int segment); @Override void deleteToken(String processorName, int segment); @Override boolean requiresExplicitSegmentInitialization(); @Override int[] fetchSegments(String processorName); @Deprecated void ensureIndexes();  }