예제 #1
0
        public async Task ExponentialBackoff503TooFewRetriesTest()
        {
            // Construct new ExponentialBackOffSettings:
            var exponentialBackOffSettings = new ExponentialBackOffSettings(2, TimeSpan.FromMilliseconds(250), TimeSpan.FromSeconds(30));

            // This needs to be a valid Service Account Credentials File. Can't mock it away:
            var settings = FileBasedFcmClientSettings.CreateFromFile("project", @"D:\serviceAccountKey.json", exponentialBackOffSettings);

            // Initialize a new FcmHttpClient to send to localhost:
            var client = new FcmHttpClient(settings);

            // Construct a Fake Message:
            var builder = new HttpRequestMessageBuilder("http://localhost:8081/return503_UntilRequestFour", HttpMethod.Get);

            CancellationToken longLivingCancellationToken = new CancellationTokenSource(TimeSpan.FromMinutes(5)).Token;

            bool fcmHttpExceptionWasThrown = false;

            try
            {
                await client.SendAsync(builder, longLivingCancellationToken);
            }
            catch (FcmHttpException)
            {
                fcmHttpExceptionWasThrown = true;
            }

            Assert.IsTrue(fcmHttpExceptionWasThrown);
        }
예제 #2
0
        public static FcmClientSettings CreateFromFile(string credentialsFileName, ExponentialBackOffSettings exponentialBackOffSettings)
        {
            var credentials = ReadCredentialsFromFile(credentialsFileName);
            var project     = GetProjectId(credentialsFileName, credentials);

            return(new FcmClientSettings(project, credentials, exponentialBackOffSettings));
        }
예제 #3
0
 public FcmClientSettings(string project, string credentials, ExponentialBackOffSettings exportExponentialBackOffSettings)
 {
     Project     = project;
     Credentials = credentials;
     ExponentialBackOffSettings = exportExponentialBackOffSettings;
 }
예제 #4
0
        public static FcmClientSettings CreateFromStream(string project, Stream credentialsStream, ExponentialBackOffSettings exponentialBackOffSettings)
        {
            var credentials = ReadCredentialsFromStream(credentialsStream);

            return(new FcmClientSettings(project, credentials, exponentialBackOffSettings));
        }