### Question:
AbstractSofaRpcFilter extends Filter { @Override public boolean needToLoad(FilterInvoker invoker) { AbstractInterfaceConfig<?, ?> config = invoker.getConfig(); String enabled = config.getParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED); if (StringUtils.isNotBlank(enabled)) { return Boolean.parseBoolean(enabled); } return RpcConfigs.getOrDefaultValue(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, true); }  @Override boolean needToLoad(FilterInvoker invoker);  }### Answer:
@Test public void testNeedToLoadProvider() { SentinelSofaRpcProviderFilter providerFilter = new SentinelSofaRpcProviderFilter(); ProviderConfig providerConfig = new ProviderConfig(); providerConfig.setInterfaceId(Serializer.class.getName()); providerConfig.setId("AAA"); FilterInvoker invoker = new FilterInvoker(null, null, providerConfig); assertTrue(providerFilter.needToLoad(invoker)); providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false"); assertFalse(providerFilter.needToLoad(invoker)); providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, ""); assertTrue(providerFilter.needToLoad(invoker)); RpcConfigs.putValue(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false"); assertFalse(providerFilter.needToLoad(invoker)); }
@Test public void testNeedToLoadConsumer() { SentinelSofaRpcConsumerFilter consumerFilter = new SentinelSofaRpcConsumerFilter(); ConsumerConfig consumerConfig = new ConsumerConfig(); consumerConfig.setInterfaceId(Serializer.class.getName()); consumerConfig.setId("BBB"); FilterInvoker invoker = new FilterInvoker(null, null, consumerConfig); assertTrue(consumerFilter.needToLoad(invoker)); consumerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false"); assertFalse(consumerFilter.needToLoad(invoker)); consumerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, ""); assertTrue(consumerFilter.needToLoad(invoker)); RpcConfigs.putValue(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false"); assertFalse(consumerFilter.needToLoad(invoker)); }
@Test public void testNeedToLoadProviderAndConsumer() { SentinelSofaRpcProviderFilter providerFilter = new SentinelSofaRpcProviderFilter(); ProviderConfig providerConfig = new ProviderConfig(); providerConfig.setInterfaceId(Serializer.class.getName()); providerConfig.setId("AAA"); FilterInvoker providerInvoker = new FilterInvoker(null, null, providerConfig); assertTrue(providerFilter.needToLoad(providerInvoker)); SentinelSofaRpcConsumerFilter consumerFilter = new SentinelSofaRpcConsumerFilter(); ConsumerConfig consumerConfig = new ConsumerConfig(); consumerConfig.setInterfaceId(Serializer.class.getName()); consumerConfig.setId("BBB"); FilterInvoker consumerInvoker = new FilterInvoker(null, null, consumerConfig); assertTrue(consumerFilter.needToLoad(consumerInvoker)); providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false"); assertFalse(providerFilter.needToLoad(providerInvoker)); assertTrue(consumerFilter.needToLoad(consumerInvoker)); providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, ""); assertTrue(providerFilter.needToLoad(providerInvoker)); RpcConfigs.putValue(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false"); assertFalse(providerFilter.needToLoad(providerInvoker)); assertFalse(consumerFilter.needToLoad(consumerInvoker)); }