Skip to content

Commit

Permalink
Merge pull request #520 from chrisdennis/issue-491-2.3.x
Browse files Browse the repository at this point in the history
Issue #491 [2.3.x]
  • Loading branch information
chrisdennis authored Oct 23, 2019
2 parents e990cd1 + de69c46 commit c069965
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,7 @@ public List<TriggerKey> selectTriggerToAcquire(Connection conn, long noLaterThan
ps.setBigDecimal(3, new BigDecimal(String.valueOf(noEarlierThan)));
rs = ps.executeQuery();

while (rs.next() && nextTriggers.size() <= maxCount) {
while (rs.next() && nextTriggers.size() < maxCount) {
nextTriggers.add(triggerKey(
rs.getString(COL_TRIGGER_NAME),
rs.getString(COL_TRIGGER_GROUP)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.quartz.impl.jdbcjobstore;

import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
Expand All @@ -27,7 +28,9 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.hamcrest.collection.IsIterableWithSize;
import org.quartz.JobPersistenceException;
import org.quartz.TriggerKey;
import org.quartz.spi.OperableTrigger;
Expand Down Expand Up @@ -135,6 +138,26 @@ public void testSelectSimpleTriggerWithDeleteBeforeSelectExtendedProps() throws
verify(persistenceDelegate).loadExtendedTriggerProperties(any(Connection.class), any(TriggerKey.class));
}

public void testSelectTriggerToAcquireHonorsMaxCount() throws SQLException {

StdJDBCDelegate jdbcDelegate = new StdJDBCDelegate();

Connection conn = mock(Connection.class);
PreparedStatement preparedStatement = mock(PreparedStatement.class);
ResultSet resultSet = mock(ResultSet.class);

when(conn.prepareStatement(anyString())).thenReturn(preparedStatement);

when(preparedStatement.executeQuery()).thenReturn(resultSet);

when(resultSet.next()).thenReturn(true);
when(resultSet.getString(anyString())).thenReturn("test");

List<TriggerKey> triggerKeys = jdbcDelegate.selectTriggerToAcquire(conn, Long.MAX_VALUE, Long.MIN_VALUE, 10);

assertThat(triggerKeys, IsIterableWithSize.<TriggerKey>iterableWithSize(10));
}

static class TestStdJDBCDelegate extends StdJDBCDelegate {

private final TriggerPersistenceDelegate testDelegate;
Expand Down

0 comments on commit c069965

Please sign in to comment.