コード例 #1
0
ファイル: DumbWorker.java プロジェクト: caricah/iotracah
  /**
   * <code>initiate</code> starts the operations of this system handler. All excecution code for the
   * plugins is expected to begin at this point.
   *
   * @throws UnRetriableException
   */
  @Override
  public void initiate() throws UnRetriableException {

    // Initiate the session reset manager.
    SessionResetManager sessionResetManager = new SessionResetManager();
    sessionResetManager.setWorker(this);
    sessionResetManager.setDatastore(this.getDatastore());
    setSessionResetManager(sessionResetManager);

    String igniteCacheName = "dumbTester";

    CacheConfiguration clCfg = new CacheConfiguration();

    clCfg.setName(igniteCacheName);
    clCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    clCfg.setCacheMode(CacheMode.PARTITIONED);
    clCfg.setMemoryMode(CacheMemoryMode.ONHEAP_TIERED);

    LruEvictionPolicy lruEvictionPolicy = new LruEvictionPolicy(5170000);
    clCfg.setEvictionPolicy(lruEvictionPolicy);

    clCfg.setSwapEnabled(true);

    // if(subscriptions instanceof  IgniteCache) {
    // subscriptions = getIgnite().createCache(clCfg);
    // }

    // Initiate unirest properties.
    Unirest.setTimeouts(5000, 5000);
  }
コード例 #2
0
ファイル: RequestAnswer.java プロジェクト: antmarpen/TFG
  /**
   * Envia una peticion GET a la URL y devuelve toda la informacion disponible sobre el cuerpo,
   * cabeceras, conexion y tiempo
   *
   * @param strURL url donde se va a hacer la peticion
   * @param headers cabeceras que se quieran agregar a la peticion
   * @param connectionTimeout connectionTimeout que se quiere para la llamada
   * @param socketTimeout socketTimeout que se quiere para la llamada
   * @param testsToPerform los tests que se quieran realizar relacionados con la llamada y el
   *     resultado de la misma
   */
  public static void sendGet(
      String strURL,
      Object headers,
      Integer connectionTimeout,
      Integer socketTimeout,
      Object testsToPerform) {
    try {
      AbstractMap<String, String> localHeaders;

      Long localTimeout;
      Long localSocketTimeout;

      localHeaders = parser(headers);

      URL url = new URL(strURL);

      SemanticAnalysis.checkURL(url);

      if (connectionTimeout == null) {
        localTimeout = RequestAnswer.CONNECTION_TIMEOUT;
      } else {
        Long aux = new Long(connectionTimeout);
        if (aux < 0) {
          localTimeout = RequestAnswer.CONNECTION_TIMEOUT;
        } else {
          localTimeout = aux;
        }
      }

      if (socketTimeout == null) {
        localSocketTimeout = RequestAnswer.SOCKET_TIMEOUT;
      } else {
        Long aux = new Long(socketTimeout);
        if (aux < 0) {
          localSocketTimeout = RequestAnswer.SOCKET_TIMEOUT;
        } else {
          localSocketTimeout = aux;
        }
      }

      Unirest.setTimeouts(localTimeout, localSocketTimeout);

      long startTime = System.currentTimeMillis();

      HttpResponse<InputStream> jsonResponse =
          Unirest.get(url.toString()).headers(localHeaders).asBinary();

      long elapsedTime = System.currentTimeMillis() - startTime;

      setValues(url, jsonResponse, localHeaders, elapsedTime);

      BufferedReader in = new BufferedReader(new InputStreamReader(jsonResponse.getRawBody()));
      String inputLine;
      StringBuilder response = new StringBuilder();

      while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
      }
      in.close();
      if (response.length() != 0) {
        responseValues.setResponse(new StringBuilder(response));
      } else {
        responseValues.setResponse(new StringBuilder("No data"));
      }

      Assertions.executeTests(testsToPerform, jsonResponse, elapsedTime, response);
    } catch (UnirestException | SocketTimeoutException e) {
      e.printStackTrace();
      exceptionMessages.put("con", "This seems to be like an error connecting to ");
    } catch (MalformedURLException e) {
      exceptionMessages.put("url", "The URL is not well formed.");
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      exceptionMessages.put("url", "The URL is not well formed.");
    } catch (NullPointerException e) {
      e.printStackTrace();
    } catch (IOException e) {
      exceptionMessages.put("con", "This seems to be like an error connecting to ");
    } catch (JsonException e) {
      exceptionMessages.put(
          "parser",
          "There has been a problem parsing your custom values (params, request headers or tests).");
    }
  }