public void RetryProxy_Fail_TransientEnumerationEvaluatesTrue() { var instance = new RetryTester(); var retryProxy = RetryProxy.Create <IRetryTester>(instance, new RetryOptions(1, TimeSpan.FromSeconds(5)), exceptionWhiteList: new Type[] { typeof(RetryTestException) }); retryProxy.Fail(); }
public void Create_PolicyNull() { var instance = new RetryProxySubject(); var policy = new CanRetryProxySubjectPolicy(5, TimeSpan.FromSeconds(5)); Assert.ThrowsException <ArgumentNullException>(() => RetryProxy.Create <IRetryProxySubject>(instance, null)); }
/// <exception cref="System.IO.IOException"/> private static ClientProtocol CreateNNProxyWithClientProtocol(IPEndPoint address, Configuration conf, UserGroupInformation ugi, bool withRetries, AtomicBoolean fallbackToSimpleAuth ) { RPC.SetProtocolEngine(conf, typeof(ClientNamenodeProtocolPB), typeof(ProtobufRpcEngine )); RetryPolicy defaultPolicy = RetryUtils.GetDefaultRetryPolicy(conf, DFSConfigKeys. DfsClientRetryPolicyEnabledKey, DFSConfigKeys.DfsClientRetryPolicyEnabledDefault , DFSConfigKeys.DfsClientRetryPolicySpecKey, DFSConfigKeys.DfsClientRetryPolicySpecDefault , typeof(SafeModeException)); long version = RPC.GetProtocolVersion(typeof(ClientNamenodeProtocolPB)); ClientNamenodeProtocolPB proxy = RPC.GetProtocolProxy <ClientNamenodeProtocolPB>(version , address, ugi, conf, NetUtils.GetDefaultSocketFactory(conf), Client.GetTimeout( conf), defaultPolicy, fallbackToSimpleAuth).GetProxy(); if (withRetries) { // create the proxy with retries IDictionary <string, RetryPolicy> methodNameToPolicyMap = new Dictionary <string, RetryPolicy >(); ClientProtocol translatorProxy = new ClientNamenodeProtocolTranslatorPB(proxy); return((ClientProtocol)RetryProxy.Create <ClientProtocol>(new DefaultFailoverProxyProvider <ClientProtocol>(typeof(ClientProtocol), translatorProxy), methodNameToPolicyMap , defaultPolicy)); } else { return(new ClientNamenodeProtocolTranslatorPB(proxy)); } }
/// <summary>Creates the namenode proxy with the passed protocol.</summary> /// <remarks> /// Creates the namenode proxy with the passed protocol. This will handle /// creation of either HA- or non-HA-enabled proxy objects, depending upon /// if the provided URI is a configured logical URI. /// </remarks> /// <param name="conf"> /// the configuration containing the required IPC /// properties, client failover configurations, etc. /// </param> /// <param name="nameNodeUri"> /// the URI pointing either to a specific NameNode /// or to a logical nameservice. /// </param> /// <param name="xface">the IPC interface which should be created</param> /// <param name="fallbackToSimpleAuth"> /// set to true or false during calls to indicate if /// a secure client falls back to simple auth /// </param> /// <returns> /// an object containing both the proxy and the associated /// delegation token service it corresponds to /// </returns> /// <exception cref="System.IO.IOException">if there is an error creating the proxy</exception> public static NameNodeProxies.ProxyAndInfo <T> CreateProxy <T>(Configuration conf, URI nameNodeUri, AtomicBoolean fallbackToSimpleAuth) { System.Type xface = typeof(T); AbstractNNFailoverProxyProvider <T> failoverProxyProvider = CreateFailoverProxyProvider (conf, nameNodeUri, xface, true, fallbackToSimpleAuth); if (failoverProxyProvider == null) { // Non-HA case return(CreateNonHAProxy(conf, NameNode.GetAddress(nameNodeUri), xface, UserGroupInformation .GetCurrentUser(), true, fallbackToSimpleAuth)); } else { // HA case DFSClient.Conf config = new DFSClient.Conf(conf); T proxy = (T)RetryProxy.Create(xface, failoverProxyProvider, RetryPolicies.FailoverOnNetworkException (RetryPolicies.TryOnceThenFail, config.maxFailoverAttempts, config.maxRetryAttempts , config.failoverSleepBaseMillis, config.failoverSleepMaxMillis)); Text dtService; if (failoverProxyProvider.UseLogicalURI()) { dtService = HAUtil.BuildTokenServiceForLogicalUri(nameNodeUri, HdfsConstants.HdfsUriScheme ); } else { dtService = SecurityUtil.BuildTokenService(NameNode.GetAddress(nameNodeUri)); } return(new NameNodeProxies.ProxyAndInfo <T>(proxy, dtService, NameNode.GetAddress( nameNodeUri))); } }
public void RetryProxy_Fail_ExceedMaxAttempts() { var instance = new RetryTester(); var retryProxy = RetryProxy.Create <IRetryTester>(instance, new RetryOptions(1, TimeSpan.FromSeconds(60))); retryProxy.Fail(); }
public void RetryProxy_Fail_NotTransientByEnumerable() { var instance = new RetryTester(); var retryProxy = RetryProxy.Create <IRetryTester>(instance, new RetryOptions(5, TimeSpan.FromSeconds(60)), exceptionWhiteList: new Type[] { typeof(NullReferenceException) }); retryProxy.Fail(); }
public void RetryProxy_Fail_NotTransientByFunction() { var instance = new RetryTester(); var retryProxy = RetryProxy.Create <IRetryTester>(instance, new RetryOptions(5, TimeSpan.FromSeconds(5)), exceptionBlackList: new Type[] { typeof(RetryTestException) }); retryProxy.Fail(); }
protected internal static T CreateRetriableProxy <T>(Configuration conf, UserGroupInformation user, YarnRPC rpc, IPEndPoint serverAddress, RetryPolicy retryPolicy) { System.Type protocol = typeof(T); T proxy = user.DoAs(new _PrivilegedAction_89(rpc, protocol, serverAddress, conf)); return((T)RetryProxy.Create(protocol, proxy, retryPolicy)); }
public async Task InvokeSuccessAsync() { var instance = new RetryProxySubject(); var retryPolicy = new CanRetryProxySubjectPolicy(5, TimeSpan.FromSeconds(5)); var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, retryPolicy); var result = await retryProxy.SucceedAsync(); Assert.AreEqual("succeed", result); }
public void RetryProxy_Success() { var instance = new RetryTester(); var retryProxy = RetryProxy.Create <IRetryTester>(instance, new RetryOptions(5, TimeSpan.FromSeconds(5)), exceptionWhiteList: new Type[] { typeof(RetryTestException) }); var result = retryProxy.Succeed(); Assert.AreEqual("succeed", result); }
public static T CreateRMProxy <T>(Configuration conf, IPEndPoint rmAddress) { System.Type protocol = typeof(T); RetryPolicy retryPolicy = CreateRetryPolicy(conf); T proxy = Org.Apache.Hadoop.Yarn.Client.RMProxy.GetProxy <T>(conf, protocol, rmAddress ); Log.Info("Connecting to ResourceManager at " + rmAddress); return((T)RetryProxy.Create(protocol, proxy, retryPolicy)); }
public void InvokeSuccess() { var instance = new RetryProxySubject(); var retryTest = new CanRetryProxySubjectException(); var retryOptions = new RetryOptions(5, TimeSpan.FromSeconds(5)); var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, retryOptions, retryTest); var result = retryProxy.Succeed(); Assert.AreEqual("succeed", result); }
public SqlServerTransactionFactoryWithRetry(SqlServerTransientRetryPolicy retryPolicy) { if (retryPolicy == null) { throw new ArgumentNullException(nameof(retryPolicy)); } _proxy = RetryProxy.Create <ITransactionFactory>( new TransactionFactory(), retryPolicy); }
public SqlServerConnectionFactoryWithRetry(SqlServerTransientRetryPolicy retryPolicy, IConnectionStringFactory connectionStringFactory) { if (retryPolicy == null) { throw new ArgumentNullException(nameof(retryPolicy)); } _proxy = RetryProxy.Create <IConnectionFactory>( connectionStringFactory == null ? new SqlServerConnectionFactory() : new SqlServerConnectionFactory(connectionStringFactory), retryPolicy); }
public SqliteConnectionFactoryWithRetry(SqliteTransientRetryPolicy retryPolicy, string connectionString) : base() { if (retryPolicy == null) { throw new ArgumentNullException(nameof(retryPolicy)); } _proxy = RetryProxy.Create <IConnectionFactory>( string.IsNullOrEmpty(connectionString) ? new SqliteConnectionFactory() : new SqliteConnectionFactory(connectionString), retryPolicy); }
public virtual void TestWrappedStopProxy() { TestRPC.StoppedProtocol wrappedProxy = RPC.GetProxy <TestRPC.StoppedProtocol>(TestRPC.StoppedProtocol .versionID, null, conf); TestRPC.StoppedInvocationHandler invocationHandler = (TestRPC.StoppedInvocationHandler )Proxy.GetInvocationHandler(wrappedProxy); TestRPC.StoppedProtocol proxy = (TestRPC.StoppedProtocol)RetryProxy.Create <TestRPC.StoppedProtocol >(wrappedProxy, RetryPolicies.RetryForever); Assert.Equal(0, invocationHandler.GetCloseCalled()); RPC.StopProxy(proxy); Assert.Equal(1, invocationHandler.GetCloseCalled()); }
public SqlServerTransactionFactoryWithRetry(RetryOptions retryOptions) { if (retryOptions == null) { throw new ArgumentNullException(nameof(retryOptions)); } _proxy = RetryProxy.Create <ITransactionFactory>( new TransactionFactory(), retryOptions, new SqlServerTransientErrorTester()); }
public SqliteConnectionFactoryWithRetry(RetryOptions retryOptions, string connectionString) : base() { if (retryOptions == null) { throw new ArgumentNullException(nameof(retryOptions)); } _proxy = RetryProxy.Create <IConnectionFactory>( String.IsNullOrEmpty(connectionString) ? new SqliteConnectionFactory() : new SqliteConnectionFactory(connectionString), retryOptions, new SqliteTransientErrorTester()); }
public void Create_OptionsNull() { var instance = new RetryProxySubject(); var options = new RetryOptions(5, TimeSpan.FromSeconds(5)); var canRetryTester = new CanRetryProxySubjectException(); try { var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, null, canRetryTester); } catch (ArgumentNullException ex) { Assert.AreEqual(nameof(options), ex.ParamName); throw; } }
public void InvokeFailure_RetryForbidden() { var instance = new RetryProxySubject(); var retryPolicy = new CanNotRetryProxySubjectPolicy(5, TimeSpan.FromMinutes(15)); var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, retryPolicy); try { var result = retryProxy.Fail(); } catch (RetryException ex) { Assert.IsTrue(ex.InnerException is ProxySubjectTestException); Assert.AreEqual(1, ex.RetrySession.Attempts); Assert.AreEqual(ex.RetrySession.Attempts, ex.RetrySession.Exceptions.Count); throw; } }
public void InvokeFailure_RetryForbidden() { var instance = new RetryProxySubject(); var retryTest = new CanNotRetryProxySubjectException(); var retryOptions = new RetryOptions(5, TimeSpan.FromSeconds(5)); var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, retryOptions, retryTest); try { var result = retryProxy.Fail(); } catch (RetryException ex) { Assert.IsTrue(ex.InnerException is ProxySubjectTestException); Assert.AreEqual(1, ex.Attempts); Assert.AreEqual(ex.Attempts, ex.Exceptions.Count); throw; } }
public async Task InvokeFailure_TimeoutExceededAsync() { var instance = new RetryProxySubject(); var retryPolicy = new CanRetryProxySubjectPolicy(10000, TimeSpan.FromSeconds(1)); var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, retryPolicy); try { var result = await retryProxy.FailAsync(); } catch (RetryException ex) { Assert.IsTrue(ex.RetrySession.Exceptions.Count > 0); Assert.IsTrue(ex.RetrySession.Exceptions[0] is ProxySubjectTestException); Assert.IsTrue(ex.RetrySession.ElapsedTime >= TimeSpan.FromSeconds(1)); Assert.AreEqual(ex.RetrySession.Attempts, ex.RetrySession.Exceptions.Count); throw; } }
public async Task InvokeFailure_RetryForbiddenAsync() { var instance = new RetryProxySubject(); var retryPolicy = new CanNotRetryProxySubjectPolicy(5, TimeSpan.FromSeconds(5)); var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, retryPolicy); //Assert.ThrowsException<RetryNotAllowedException>() try { var result = await retryProxy.FailAsync(); } catch (RetryException ex) { Assert.IsTrue(ex.InnerException is ProxySubjectTestException); Assert.AreEqual(1, ex.RetrySession.Attempts); Assert.AreEqual(ex.RetrySession.Attempts, ex.RetrySession.Exceptions.Count); throw; } }
public void InvokeFailure_MaxAttemptsExceeded() { var instance = new RetryProxySubject(); var retryPolicy = new CanRetryProxySubjectPolicy(5, TimeSpan.FromSeconds(60)); var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, retryPolicy); try { var result = retryProxy.Fail(); } catch (RetryException ex) { Assert.IsTrue(ex.RetrySession.Exceptions.Count > 0); Assert.IsTrue(ex.RetrySession.Exceptions[0] is ProxySubjectTestException); Assert.AreEqual(5, ex.RetrySession.Attempts); Assert.AreEqual(ex.RetrySession.Attempts, ex.RetrySession.Exceptions.Count); throw; } }
public async Task InvokeFailure_MaxAttemptsExceededAsync() { var instance = new RetryProxySubject(); var retryTest = new CanRetryProxySubjectException(); var retryOptions = new RetryOptions(5, TimeSpan.FromSeconds(60)); var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, retryOptions, retryTest); try { var result = await retryProxy.FailAsync(); } catch (RetryException ex) { Assert.IsTrue(ex.Exceptions.Count > 0); Assert.IsTrue(ex.Exceptions[0] is ProxySubjectTestException); Assert.AreEqual(5, ex.Attempts); Assert.AreEqual(ex.Attempts, ex.Exceptions.Count); throw; } }
public void InvokeFailure_TimeoutExceeded() { var instance = new RetryProxySubject(); var retryTest = new CanRetryProxySubjectException(); var retryOptions = new RetryOptions(int.MaxValue, TimeSpan.FromSeconds(1)); var retryProxy = RetryProxy.Create <IRetryProxySubject>(instance, retryOptions, retryTest); try { var result = retryProxy.Fail(); } catch (RetryException ex) { Assert.IsTrue(ex.Exceptions.Count > 0); Assert.IsTrue(ex.Exceptions[0] is ProxySubjectTestException); Assert.IsTrue(ex.Duration >= TimeSpan.FromSeconds(1)); Assert.AreEqual(ex.Attempts, ex.Exceptions.Count); throw; } }
protected internal static T CreateRMProxy <T>(Configuration configuration, Org.Apache.Hadoop.Yarn.Client.RMProxy instance) { System.Type protocol = typeof(T); YarnConfiguration conf = (configuration is YarnConfiguration) ? (YarnConfiguration )configuration : new YarnConfiguration(configuration); RetryPolicy retryPolicy = CreateRetryPolicy(conf); if (HAUtil.IsHAEnabled(conf)) { RMFailoverProxyProvider <T> provider = instance.CreateRMFailoverProxyProvider(conf , protocol); return((T)RetryProxy.Create(protocol, provider, retryPolicy)); } else { IPEndPoint rmAddress = instance.GetRMAddress(conf, protocol); Log.Info("Connecting to ResourceManager at " + rmAddress); T proxy = Org.Apache.Hadoop.Yarn.Client.RMProxy.GetProxy <T>(conf, protocol, rmAddress ); return((T)RetryProxy.Create(protocol, proxy, retryPolicy)); } }
/// <exception cref="System.IO.IOException"/> private static NamenodeProtocol CreateNNProxyWithNamenodeProtocol(IPEndPoint address , Configuration conf, UserGroupInformation ugi, bool withRetries) { NamenodeProtocolPB proxy = (NamenodeProtocolPB)CreateNameNodeProxy(address, conf, ugi, typeof(NamenodeProtocolPB)); if (withRetries) { // create the proxy with retries RetryPolicy timeoutPolicy = RetryPolicies.ExponentialBackoffRetry(5, 200, TimeUnit .Milliseconds); IDictionary <string, RetryPolicy> methodNameToPolicyMap = new Dictionary <string, RetryPolicy >(); methodNameToPolicyMap["getBlocks"] = timeoutPolicy; methodNameToPolicyMap["getAccessKeys"] = timeoutPolicy; NamenodeProtocol translatorProxy = new NamenodeProtocolTranslatorPB(proxy); return((NamenodeProtocol)RetryProxy.Create <NamenodeProtocol>(translatorProxy, methodNameToPolicyMap )); } else { return(new NamenodeProtocolTranslatorPB(proxy)); } }
public SqliteExpressionReaderWithRetry(DbConnection dbConnection, SqliteTransientRetryPolicy retryPolicy) { var instance = new ExpressionReader(dbConnection, new SqliteParameterFactory(), new SqliteDataAdapterFactory()); _proxy = RetryProxy.Create <IExpressionReader>(instance, retryPolicy); }
public SqlServerCommandProcedureWithRetry(IDataComponentFactory factory, RetryOptions retryOptions) { var instance = new CommandProcedure(factory); _proxy = RetryProxy.Create <ICommandProcedure>(instance, retryOptions, new SqlServerTransientErrorTester()); }