<commit_before>/**
 *
 */
package test.utils;

import javastrava.api.v3.service.Strava;
import javastrava.api.v3.service.exception.StravaAPIRateLimitException;
import javastrava.api.v3.service.exception.StravaServiceUnavailableException;

/**
 * @author danshannon
 *
 */
public class RateLimitedTestRunner {
	private static Strava strava = null;

	static {
		try {
			strava = TestUtils.strava();
		} catch (final StravaServiceUnavailableException e) {
			waitForServiceRestoration();
		}
	}

	public static void run(final TestCallback t) throws Exception {
		boolean loop = true;
		while (loop) {
			try {
				t.test();
				loop = false;
			} catch (final StravaAPIRateLimitException e) {
				waitForRateLimit();
			} catch (final StravaServiceUnavailableException e) {
				waitForServiceRestoration();
			}
		}
	}

	/**
	 *
	 */
	private static void waitForServiceRestoration() {
		boolean loop = true;
		while (loop) {
			try {
				System.out.println("WARN - Strava temporarily unavailable (503 error) - pausing execution for 60 seconds");
				Thread.sleep(60000l);
			} catch (final InterruptedException e) {
				// ignore
			}
			try {
				strava = TestUtils.strava();
				strava.getAuthenticatedAthlete();
				// If the call works, then we didn't get a service unavailable exception so we're good to go
				loop = false;
			} catch (final StravaServiceUnavailableException e) {
				loop = true;
			}
		}

	}

	private static void waitForRateLimit() {
		boolean loop = true;
		while (loop) {
			try {
				System.out.println("WARN - Rate limit exceeded - pausing test execution for 15 seconds");
				Thread.sleep(15000l);
			} catch (final InterruptedException e) {
				// ignore
			}
			try {
				strava.getAuthenticatedAthlete();
				// If the call to Strava works then we didn't get a rate limit exception so we're good to go
				loop = false;
			} catch (final StravaAPIRateLimitException e) {
				loop = true;
			}
		}
	}
}<commit_msg>Fix issue javastrava-api #61 See https://github.com/danshannon/javastravav3api/issues/61<commit_after>/**
 *
 */
package test.utils;

import javastrava.api.v3.service.exception.StravaAPIRateLimitException;
import javastrava.api.v3.service.exception.StravaServiceUnavailableException;

/**
 * @author danshannon
 *
 */
public class RateLimitedTestRunner {
	public static void run(final TestCallback t) throws Exception {
		boolean loop = true;
		while (loop) {
			try {
				t.test();
				loop = false;
			} catch (final StravaAPIRateLimitException e) {
				waitForRateLimit();
			} catch (final StravaServiceUnavailableException e) {
				waitForServiceRestoration();
			}
		}
	}

	/**
	 *
	 */
	private static void waitForServiceRestoration() {
		boolean loop = true;
		while (loop) {
			try {
				System.out.println("WARN - Strava temporarily unavailable (503 error) - pausing execution for 60 seconds");
				Thread.sleep(60000l);
			} catch (final InterruptedException e) {
				// ignore
			}
			try {
				TestUtils.strava().getAuthenticatedAthlete();
				// If the call works, then we didn't get a service unavailable exception so we're good to go
				loop = false;
			} catch (final StravaServiceUnavailableException e) {
				loop = true;
			}
		}

	}

	private static void waitForRateLimit() {
		boolean loop = true;
		while (loop) {
			try {
				System.out.println("WARN - Rate limit exceeded - pausing test execution for 15 seconds");
				Thread.sleep(15000l);
			} catch (final InterruptedException e) {
				// ignore
			}
			try {
				TestUtils.strava().getAuthenticatedAthlete();
				// If the call to Strava works then we didn't get a rate limit exception so we're good to go
				loop = false;
			} catch (final StravaAPIRateLimitException e) {
				loop = true;
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.10402144772117962, 'fraction_numerical': 0.011796246648793566, 'mean_word_length': 3.2397727272727272, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2762471', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1185, 'n_words': 319}