/**
   * Test that the legacy manual disconnect()/reconnect() chain works as expected in the given
   * environment. Similar to {@link #testManualDisconnectChain} expect that here we force the
   * session to acquire and hold JDBC resources prior to disconnecting.
   */
  @Test
  public final void testManualDisconnectWithOpenResources() throws Throwable {
    prepare();
    Session sessionUnderTest = getSessionUnderTest();

    Silly silly = new Silly("tester");
    sessionUnderTest.save(silly);
    sessionUnderTest.flush();

    sessionUnderTest.createQuery("from Silly").iterate();

    disconnect(sessionUnderTest);
    SerializationHelper.serialize(sessionUnderTest);
    checkSerializedState(sessionUnderTest);

    reconnect(sessionUnderTest);
    sessionUnderTest.createQuery("from Silly").scroll();

    disconnect(sessionUnderTest);
    SerializationHelper.serialize(sessionUnderTest);
    checkSerializedState(sessionUnderTest);

    reconnect(sessionUnderTest);
    sessionUnderTest.delete(silly);
    sessionUnderTest.flush();

    release(sessionUnderTest);
    done();
  }
  /** Tests to validate that a session holding JDBC resources will not be allowed to serialize. */
  @Test
  public final void testEnabledFilterSerialization() throws Throwable {
    prepare();
    Session sessionUnderTest = getSessionUnderTest();

    sessionUnderTest.enableFilter("nameIsNull");
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));
    disconnect(sessionUnderTest);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));

    byte[] bytes = SerializationHelper.serialize(sessionUnderTest);
    checkSerializedState(sessionUnderTest);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));
    reconnect(sessionUnderTest);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));
    disconnect(sessionUnderTest);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));

    Session s2 = (Session) SerializationHelper.deserialize(bytes);
    checkDeserializedState(s2);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));
    reconnect(s2);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));

    disconnect(s2);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));
    reconnect(s2);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));

    release(sessionUnderTest);
    release(s2);
    done();
  }
Пример #3
0
  public GeolocAddress geolocByLatitudeLongitude(final String latitude, final String longitude) {
    GeolocAddress geolocAddress = null;
    GoogleGeoCode geoCode = geolocGoogleWithLatitudeLongitude(latitude, longitude);
    if (geoCode != null && "OVER_QUERY_LIMIT".equals(geoCode.getStatus())) {
      logger.error("API Geoloc returns message OVER_QUERY_LIMIT: " + geoCode.getErrorMessage());
      engineSettingService.flagSettingGoogleGeolocationApiOverQuota();
      return geolocAddress;
    }

    if (geoCode != null && geoCode.getResults().size() > 0) {
      GoogleGeoCodeResult googleGeoCodeResult = geoCode.getResults().get(0);
      String formatedAdress = googleGeoCodeResult.getFormattedAddress();
      formatedAdress = formatedAdress.replace(" ", "+").replace("\"", "+");

      geolocAddress = new GeolocAddress();
      geolocAddress.setAddress(googleGeoCodeResult.getAddress());
      geolocAddress.setPostalCode(googleGeoCodeResult.getPostalCode());
      geolocAddress.setCity(googleGeoCodeResult.getCity());
      geolocAddress.setCountry(googleGeoCodeResult.getCountryCode());
      geolocAddress.setJson(SerializationHelper.serialize(geoCode));
      geolocAddress.setFormatedAddress(formatedAdress);
      geolocAddress.setLatitude(latitude);
      geolocAddress.setLongitude(longitude);

      // SANITY CHECK : DON'T SAVE AN ADDRESS WHICH ALREADY EXIST BUT WAS LOCATED WITH LAT/LONG
      // DIFFERENT
      GeolocAddress geolocGeolocAddress =
          geolocDao.getGeolocAddressByFormatedAddress(formatedAdress);
      if (geolocGeolocAddress == null) {
        geolocAddress = geolocDao.saveOrUpdateGeolocAddress(geolocAddress);
      }
    }
    return geolocAddress;
  }
Пример #4
0
  public GeolocAddress geolocByAddress(
      final String address, final String postalCode, final String city, final String country) {
    GeolocAddress geolocAddress = null;
    String formatedAddress = encodeGoogleAddress(address, postalCode, city, country);
    GoogleGeoCode geoCode = geolocGoogleWithAddress(formatedAddress);
    if (geoCode != null && "OVER_QUERY_LIMIT".equals(geoCode.getStatus())) {
      logger.error("API Geoloc returns message OVER_QUERY_LIMIT: " + geoCode.getErrorMessage());
      engineSettingService.flagSettingGoogleGeolocationApiOverQuota();
      return geolocAddress;
    }

    if (geoCode != null) {
      geolocAddress = new GeolocAddress();
      geolocAddress.setAddress(address);
      geolocAddress.setPostalCode(postalCode);
      geolocAddress.setCity(city);
      geolocAddress.setCountry(country);
      geolocAddress.setJson(SerializationHelper.serialize(geoCode));
      geolocAddress.setFormatedAddress(formatedAddress);
      geolocAddress.setLatitude(geoCode.getLatitude());
      geolocAddress.setLongitude(geoCode.getLongitude());
      geolocAddress = geolocDao.saveOrUpdateGeolocAddress(geolocAddress);
    }
    return geolocAddress;
  }
  /**
   * Test that the legacy manual disconnect()/reconnect() chain works as expected in the given
   * environment.
   */
  @Test
  public final void testManualDisconnectChain() throws Throwable {
    prepare();
    Session sessionUnderTest = getSessionUnderTest();

    disconnect(sessionUnderTest);

    byte[] bytes = SerializationHelper.serialize(sessionUnderTest);
    checkSerializedState(sessionUnderTest);
    Session s2 = (Session) SerializationHelper.deserialize(bytes);
    checkDeserializedState(s2);

    reconnect(s2);

    disconnect(s2);
    reconnect(s2);

    release(sessionUnderTest);
    release(s2);
    done();
  }
  @Test
  public void testSerializationFailsOnAfterStatementAggressiveReleaseWithOpenResources()
      throws Throwable {
    prepare();
    Session s = getSessionUnderTest();

    Silly silly = new Silly("silly");
    s.save(silly);

    // this should cause the CM to obtain a connection, and then release it
    s.flush();

    // both scroll() and iterate() cause batching to hold on
    // to resources, which should make aggressive-release not release
    // the connection (and thus cause serialization to fail)
    ScrollableResults sr = s.createQuery("from Silly").scroll();

    try {
      SerializationHelper.serialize(s);
      fail(
          "Serialization allowed on connected session; or aggressive release released connection with open resources");
    } catch (IllegalStateException e) {
      // expected behavior
    }

    // getting the first row only because SybaseASE15Dialect throws NullPointerException
    // if data is not read before closing the ResultSet
    sr.next();

    // Closing the ScrollableResults does currently force batching to
    // aggressively release the connection
    sr.close();
    SerializationHelper.serialize(s);

    s.delete(silly);
    s.flush();

    release(s);
    done();
  }
  /** Test that a session which has been manually disconnected will be allowed to serialize. */
  @Test
  public final void testManualDisconnectedSerialization() throws Throwable {
    prepare();
    Session sessionUnderTest = getSessionUnderTest();

    disconnect(sessionUnderTest);

    SerializationHelper.serialize(sessionUnderTest);
    checkSerializedState(sessionUnderTest);

    release(sessionUnderTest);
    done();
  }
Пример #8
0
  public GeolocCity geolocByCityAndCountry(final String city, final String country) {
    GeolocCity geolocCity = null;
    String addressParam = encodeGoogleAddress(null, null, city, country);
    GoogleGeoCode geoCode = geolocGoogleWithAddress(addressParam);
    if (geoCode != null && "OVER_QUERY_LIMIT".equals(geoCode.getStatus())) {
      logger.error("API Geoloc returns message OVER_QUERY_LIMIT: " + geoCode.getErrorMessage());
      engineSettingService.flagSettingGoogleGeolocationApiOverQuota();
      return geolocCity;
    }

    if (geoCode != null) {
      geolocCity = new GeolocCity();
      geolocCity.setCity(city);
      geolocCity.setCountry(country);
      geolocCity.setJson(SerializationHelper.serialize(geoCode));
      geolocCity.setLatitude(geoCode.getLatitude());
      geolocCity.setLongitude(geoCode.getLongitude());
      if (city == null) {
        // SANITY CHECK : DON'T SAVE A CITY AS NULL TOO MANY TIME
        GeolocCity geolocCityCheck = geolocDao.getGeolocCityByCountryWithNullCity(country);
        if (geolocCityCheck == null) {
          try {
            geolocCity = geolocDao.saveOrUpdateGeolocCity(geolocCity);
          } catch (Exception e) {
            logger.error(
                "Can't save GeolocCity: City: '"
                    + geolocCity.getCity()
                    + "', Country: '"
                    + geolocCity.getCountry()
                    + "'",
                e);
          }
        }
      } else {
        try {
          geolocCity = geolocDao.saveOrUpdateGeolocCity(geolocCity);
        } catch (Exception e) {
          logger.error(
              "Can't save GeolocCity: City: '"
                  + geolocCity.getCity()
                  + "', Country: '"
                  + geolocCity.getCountry()
                  + "'",
              e);
        }
      }
    }
    return geolocCity;
  }
  /** Tests to validate that a session holding JDBC resources will not be allowed to serialize. */
  @Test
  public final void testConnectedSerialization() throws Throwable {
    prepare();
    Session sessionUnderTest = getSessionUnderTest();

    // force the connection to be retained
    sessionUnderTest.createQuery("from Silly").scroll();

    try {
      SerializationHelper.serialize(sessionUnderTest);

      fail("Serialization of connected session allowed!");
    } catch (IllegalStateException e) {
      // expected behaviour
    } finally {
      release(sessionUnderTest);
      done();
    }
  }
  @Test
  public void testSerializationOnAfterStatementAggressiveRelease() throws Throwable {
    prepare();
    try {
      Session s = getSessionUnderTest();
      Silly silly = new Silly("silly");
      s.save(silly);

      // this should cause the CM to obtain a connection, and then release it
      s.flush();

      // We should be able to serialize the session at this point...
      SerializationHelper.serialize(s);

      s.delete(silly);
      s.flush();

      release(s);
    } finally {
      done();
    }
  }