SimpleJdbcLock extends AbstractSimpleLock { @Override protected boolean release(final String key, final String storeId, final String token) { return lockSingleKeyService.release(key, storeId, token); } SimpleJdbcLock(final Supplier<String> tokenSupplier, final JdbcLockSingleKeyService lockSingleKeyService);   }
@Test public void shouldRelease() { new SimpleJdbcInsert(jdbcTemplate) .withTableName("locks") .usingGeneratedKeyColumns("id") .executeAndReturnKey(values("1", "abc")); final var released = lock.release(Collections.singletonList("1"), "locks", "abc"); assertThat(released).isTrue(); assertThat(jdbcTemplate.queryForList("SELECT * FROM locks")).isNullOrEmpty(); }
@Test public void shouldNotRelease() { new SimpleJdbcInsert(jdbcTemplate) .withTableName("locks") .usingGeneratedKeyColumns("id") .executeAndReturnKey(values("1", "def")); lock.release(Collections.singletonList("1"), "locks", "abc"); final var acquiredLockMap = jdbcTemplate.queryForObject("SELECT * FROM locks WHERE id = 1", new ColumnMapRowMapper()); assertThat(acquiredLockMap).containsAllEntriesOf(values("1", "def")); }