test_class.declarator: protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension()
test_class.modifier: private
test_class.original_string: private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
test_class.type: Protocol
test_class.var_name: protocol
test_class.declarator: proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension()
test_class.modifier: private
test_class.original_string: private ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
test_class.type: ProxyFactory
test_class.var_name: proxy
test_class.declarator: redisServer
test_class.modifier: private
test_class.original_string: private RedisServer redisServer;
test_class.type: RedisServer
test_class.var_name: redisServer
test_class.declarator: registryUrl
test_class.modifier: private
test_class.original_string: private URL registryUrl;
test_class.type: URL
test_class.var_name: registryUrl
test_class.declarator: name = new TestName()
test_class.modifier: @Rule
      public
test_class.original_string: @Rule
      public TestName name = new TestName();
test_class.type: TestName
test_class.var_name: name
test_class.file: dubbo-rpc/dubbo-rpc-redis/src/test/java/com/alibaba/dubbo/rpc/protocol/redis/RedisProtocolTest.java
test_class.identifier: RedisProtocolTest
test_case.body: @Test
      public void testAuthRedis() {
          // default db.index=0
          Invoker<IDemoService> refer = protocol.refer(IDemoService.class,
                  registryUrl
                          .addParameter("max.idle", 10)
                          .addParameter("max.active", 20));
          IDemoService demoService = this.proxy.getProxy(refer);
  
          String value = demoService.get("key");
          assertThat(value, is(nullValue()));
  
          demoService.set("key", "newValue");
          value = demoService.get("key");
          assertThat(value, is("newValue"));
  
          demoService.delete("key");
          value = demoService.get("key");
          assertThat(value, is(nullValue()));
  
          refer.destroy();
  
          //change db.index=1
          String password = "123456";
          int database = 1;
          this.registryUrl = this.registryUrl.setPassword(password).addParameter("db.index", database);
          refer = protocol.refer(IDemoService.class,
                  registryUrl
                          .addParameter("max.idle", 10)
                          .addParameter("max.active", 20));
          demoService = this.proxy.getProxy(refer);
  
          demoService.set("key", "newValue");
          value = demoService.get("key");
          assertThat(value, is("newValue"));
  
          // jedis gets the result comparison
          JedisPool pool = new JedisPool(new GenericObjectPoolConfig(), "localhost", registryUrl.getPort(), 2000, password, database, (String)null);
          Jedis jedis = null;
          try {
              jedis = pool.getResource();
              byte[] valueByte = jedis.get("key".getBytes());
              Serialization serialization = ExtensionLoader.getExtensionLoader(Serialization.class).getExtension(this.registryUrl.getParameter(Constants.SERIALIZATION_KEY, "java"));
              ObjectInput oin = serialization.deserialize(this.registryUrl, new ByteArrayInputStream(valueByte));
              String actual = (String) oin.readObject();
              assertThat(value, is(actual));
          } catch(Exception e) {
              Assert.fail("jedis gets the result comparison is error!");
          } finally {
              if (jedis != null) {
                  jedis.close();
              }
              pool.destroy();
          }
  
          demoService.delete("key");
          value = demoService.get("key");
          assertThat(value, is(nullValue()));
  
          refer.destroy();
      }
test_case.class_method_signature: RedisProtocolTest.testAuthRedis()
test_case.full_signature: @Test public void testAuthRedis()
test_case.identifier: testAuthRedis
test_case.invocations: refer addParameter addParameter getProxy get assertThat is nullValue set get assertThat is delete get assertThat is nullValue destroy addParameter setPassword refer addParameter addParameter getProxy set get assertThat is getPort getResource get getBytes getExtension getExtensionLoader getParameter deserialize readObject assertThat is fail close destroy delete get assertThat is nullValue destroy
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testAuthRedis()
focal_class.declarator: DEFAULT_PORT = 6379
focal_class.modifier: public static final
focal_class.original_string: public static final int DEFAULT_PORT = 6379;
focal_class.type: int
focal_class.var_name: DEFAULT_PORT
focal_class.file: dubbo-rpc/dubbo-rpc-redis/src/main/java/com/alibaba/dubbo/rpc/protocol/redis/RedisProtocol.java
focal_class.identifier: RedisProtocol
focal_class.class_method_signature: RedisProtocol.getDefaultPort()
focal_class.full_signature: @Override public int getDefaultPort()
focal_class.identifier: getDefaultPort
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getDefaultPort()
focal_class.class_method_signature: RedisProtocol.export(final Invoker<T> invoker)
focal_class.full_signature: @Override public Exporter<T> export(final Invoker<T> invoker)
focal_class.identifier: export
focal_class.modifiers: @Override public
focal_class.parameters: (final Invoker<T> invoker)
focal_class.return: Exporter<T>
focal_class.signature: Exporter<T> export(final Invoker<T> invoker)
focal_class.class_method_signature: RedisProtocol.getSerialization(URL url)
focal_class.full_signature: private Serialization getSerialization(URL url)
focal_class.identifier: getSerialization
focal_class.modifiers: private
focal_class.parameters: (URL url)
focal_class.return: Serialization
focal_class.signature: Serialization getSerialization(URL url)
focal_class.class_method_signature: RedisProtocol.refer(final Class<T> type, final URL url)
focal_class.full_signature: @Override public Invoker<T> refer(final Class<T> type, final URL url)
focal_class.identifier: refer
focal_class.modifiers: @Override public
focal_class.parameters: (final Class<T> type, final URL url)
focal_class.return: Invoker<T>
focal_class.signature: Invoker<T> refer(final Class<T> type, final URL url)
focal_class.superclass: extends AbstractProtocol
focal_method.body: @Override
      public <T> Invoker<T> refer(final Class<T> type, final URL url) throws RpcException {
          try {
              GenericObjectPoolConfig config = new GenericObjectPoolConfig();
              config.setTestOnBorrow(url.getParameter("test.on.borrow", true));
              config.setTestOnReturn(url.getParameter("test.on.return", false));
              config.setTestWhileIdle(url.getParameter("test.while.idle", false));
              if (url.getParameter("max.idle", 0) > 0)
                  config.setMaxIdle(url.getParameter("max.idle", 0));
              if (url.getParameter("min.idle", 0) > 0)
                  config.setMinIdle(url.getParameter("min.idle", 0));
              if (url.getParameter("max.active", 0) > 0)
                  config.setMaxTotal(url.getParameter("max.active", 0));
              if (url.getParameter("max.total", 0) > 0)
                  config.setMaxTotal(url.getParameter("max.total", 0));
              if (url.getParameter("max.wait", 0) > 0)
                  config.setMaxWaitMillis(url.getParameter("max.wait", 0));
              if (url.getParameter("num.tests.per.eviction.run", 0) > 0)
                  config.setNumTestsPerEvictionRun(url.getParameter("num.tests.per.eviction.run", 0));
              if (url.getParameter("time.between.eviction.runs.millis", 0) > 0)
                  config.setTimeBetweenEvictionRunsMillis(url.getParameter("time.between.eviction.runs.millis", 0));
              if (url.getParameter("min.evictable.idle.time.millis", 0) > 0)
                  config.setMinEvictableIdleTimeMillis(url.getParameter("min.evictable.idle.time.millis", 0));
              final JedisPool jedisPool = new JedisPool(config, url.getHost(), url.getPort(DEFAULT_PORT),
                      url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT),
                      StringUtils.isBlank(url.getPassword()) ? null : url.getPassword(),
                      url.getParameter("db.index", 0));
              final int expiry = url.getParameter("expiry", 0);
              final String get = url.getParameter("get", "get");
              final String set = url.getParameter("set", Map.class.equals(type) ? "put" : "set");
              final String delete = url.getParameter("delete", Map.class.equals(type) ? "remove" : "delete");
              return new AbstractInvoker<T>(type, url) {
                  @Override
                  protected Result doInvoke(Invocation invocation) throws Throwable {
                      Jedis resource = null;
                      try {
                          resource = jedisPool.getResource();
  
                          if (get.equals(invocation.getMethodName())) {
                              if (invocation.getArguments().length != 1) {
                                  throw new IllegalArgumentException("The redis get method arguments mismatch, must only one arguments. interface: " + type.getName() + ", method: " + invocation.getMethodName() + ", url: " + url);
                              }
                              byte[] value = resource.get(String.valueOf(invocation.getArguments()[0]).getBytes());
                              if (value == null) {
                                  return new RpcResult();
                              }
                              ObjectInput oin = getSerialization(url).deserialize(url, new ByteArrayInputStream(value));
                              return new RpcResult(oin.readObject());
                          } else if (set.equals(invocation.getMethodName())) {
                              if (invocation.getArguments().length != 2) {
                                  throw new IllegalArgumentException("The redis set method arguments mismatch, must be two arguments. interface: " + type.getName() + ", method: " + invocation.getMethodName() + ", url: " + url);
                              }
                              byte[] key = String.valueOf(invocation.getArguments()[0]).getBytes();
                              ByteArrayOutputStream output = new ByteArrayOutputStream();
                              ObjectOutput value = getSerialization(url).serialize(url, output);
                              value.writeObject(invocation.getArguments()[1]);
                              resource.set(key, output.toByteArray());
                              if (expiry > 1000) {
                                  resource.expire(key, expiry / 1000);
                              }
                              return new RpcResult();
                          } else if (delete.equals(invocation.getMethodName())) {
                              if (invocation.getArguments().length != 1) {
                                  throw new IllegalArgumentException("The redis delete method arguments mismatch, must only one arguments. interface: " + type.getName() + ", method: " + invocation.getMethodName() + ", url: " + url);
                              }
                              resource.del(String.valueOf(invocation.getArguments()[0]).getBytes());
                              return new RpcResult();
                          } else {
                              throw new UnsupportedOperationException("Unsupported method " + invocation.getMethodName() + " in redis service.");
                          }
                      } catch (Throwable t) {
                          RpcException re = new RpcException("Failed to invoke redis service method. interface: " + type.getName() + ", method: " + invocation.getMethodName() + ", url: " + url + ", cause: " + t.getMessage(), t);
                          if (t instanceof TimeoutException || t instanceof SocketTimeoutException) {
                              re.setCode(RpcException.TIMEOUT_EXCEPTION);
                          } else if (t instanceof JedisConnectionException || t instanceof IOException) {
                              re.setCode(RpcException.NETWORK_EXCEPTION);
                          } else if (t instanceof JedisDataException) {
                              re.setCode(RpcException.SERIALIZATION_EXCEPTION);
                          }
                          throw re;
                      } finally {
                          if (resource != null) {
                              try {
                                  jedisPool.returnResource(resource);
                              } catch (Throwable t) {
                                  logger.warn("returnResource error: " + t.getMessage(), t);
                              }
                          }
                      }
                  }
  
                  @Override
                  public void destroy() {
                      super.destroy();
                      try {
                          jedisPool.destroy();
                      } catch (Throwable e) {
                          logger.warn(e.getMessage(), e);
                      }
                  }
              };
          } catch (Throwable t) {
              throw new RpcException("Failed to refer redis service. interface: " + type.getName() + ", url: " + url + ", cause: " + t.getMessage(), t);
          }
      }
focal_method.class_method_signature: RedisProtocol.refer(final Class<T> type, final URL url)
focal_method.full_signature: @Override public Invoker<T> refer(final Class<T> type, final URL url)
focal_method.identifier: refer
focal_method.invocations: setTestOnBorrow getParameter setTestOnReturn getParameter setTestWhileIdle getParameter getParameter setMaxIdle getParameter getParameter setMinIdle getParameter getParameter setMaxTotal getParameter getParameter setMaxTotal getParameter getParameter setMaxWaitMillis getParameter getParameter setNumTestsPerEvictionRun getParameter getParameter setTimeBetweenEvictionRunsMillis getParameter getParameter setMinEvictableIdleTimeMillis getParameter getHost getPort getParameter isBlank getPassword getPassword getParameter getParameter getParameter getParameter equals getParameter equals getResource equals getMethodName getArguments getName getMethodName get getBytes valueOf getArguments deserialize getSerialization readObject equals getMethodName getArguments getName getMethodName getBytes valueOf getArguments serialize getSerialization writeObject getArguments set toByteArray expire equals getMethodName getArguments getName getMethodName del getBytes valueOf getArguments getMethodName getName getMethodName getMessage setCode setCode setCode returnResource warn getMessage destroy destroy warn getMessage getName getMessage
focal_method.modifiers: @Override public
focal_method.parameters: (final Class<T> type, final URL url)
focal_method.return: Invoker<T>
focal_method.signature: Invoker<T> refer(final Class<T> type, final URL url)