Assessment Test Cases Failing

Hi,

I have submitted the QEats module 6 for assessment. 6 cases failed.

The build was successful locally.

The failing test cases are:
1.
com.crio.qeats.repositoryservices.RestaurantRepositoryServiceCacheTest
restaurantsCloseByFromWarmCache(MongoTemplate)

com.crio.qeats.repositoryservices.RestaurantRepositoryServiceCacheTest
restaurantsCloseByFromColdCache(MongoTemplate)

com.crio.qeats.repositoryservices.RestaurantRepositoryServiceTest
noRestaurantsNearBy(MongoTemplate)

com.crio.qeats.repositoryservices.RestaurantRepositoryServiceTest
tooLateNoRestaurantIsOpen(MongoTemplate)

com.cr.io.qeats.repositoryservices.RestaurantRepositoryServiceTest
tooEarlyNoRestaurantIsOpen(MongoTemplate)

com.crio.qeats.repositoryservices.RestaurantRepositoryServiceTest
restaurantsCloseByAndOpenNow(MongoTemplate)

I have checked the unit test log.

For the RestaurantRepositoryServiceCacheTest, following is what I could find in the log:
com.crio.qeats.repositoryservices.RestaurantRepositoryServiceCacheTest > restaurantsCloseByFromWarmCache(MongoTemplate) FAILED
java.lang.RuntimeException at RestaurantRepositoryServiceCacheTest.java:64

For the RestaurantRepositoryServiceTest, following error thrown:
com.crio.qeats.repositoryservices.RestaurantRepositoryServiceTest > noRestaurantsNearBy(MongoTemplate) FAILED
java.lang.RuntimeException at RestaurantRepositoryServiceTest.java:67

By looking at the location where it fails, it seems, they are throwing the error in the @BeforeEach.

In @BeforeEach, the RedisServer is created and then it is started. Is something going wrong there? Can you guys help me to figure out what is happening there?

Thanks,
Raghu

Very nice debugging :open_hands: happy to see this happening instead of a context less ticket.

@anand-crio @anas-criodo

@gouravsardana can you check why this is happening?

The error was this

Could be that one of the tests is crashing due to the JedisConnectException leaving aside an unterminated redis process due to which the rest of the tests are failing with RuntimeException

Can you try try-catching the code in your repo layer where you are asking for a JedisPool resource?

In my repo layer I am getting the Jedispool in a try-with-resource-catch clause.

try (Jedis jedis = redisConfiguration.getJedisPool().getResource()) {
      
      GeoHash geoHash = GeoHash.withCharacterPrecision(latitude, longitude, 7);
      
      String restsString = jedis.get(geoHash.toBase32());
      
      List<RestaurantEntity> restaurantEntities = null;
      if (restsString != null && !restsString.equals("[]")) {
        //System.out.println("checkpoint 11 - returning the restaurants saved in Redis");
        restaurantEntities =  objectMapper.readValue(restsString, 
            new TypeReference<List<RestaurantEntity>>() {});
      } else {
        restaurantEntities = restaurantRepository.findAll();
      
        System.out.println("restaurantEntities : " + restaurantEntities);
        jedis.set(geoHash.toBase32(), objectMapper.writeValueAsString(restaurantEntities));
      }
    
      
      List<Restaurant> restaurants = new ArrayList<Restaurant>();
      ModelMapper modelMapper = new ModelMapper();
      for (RestaurantEntity rest: restaurantEntities) {
        //System.out.println("restaurant info: " + rest.getName());
        double distanceToHotel = GeoUtils.findDistanceInKm(latitude, longitude, 
            rest.getLatitude(), rest.getLongitude());
        if (distanceToHotel <=  servingRadiusInKms && isOpenNow(currentTime, rest)) {
          Restaurant restaurant = modelMapper.map(rest, Restaurant.class);
          restaurant.setName(getSanitizedString(restaurant.getName()));
          restaurants.add(restaurant);
          /*
          if (hasOnlyPrintableAsciiChars(restaurant.getName())) {
            restaurants.add(restaurant);
          }
          */
          
        }
      }
      
      return restaurants;
    } catch (RuntimeException e) {
      System.out.println("checkpoint - 6 - something is wrong: " + e.getMessage());
      throw e;
    } catch (Exception e) {
      System.out.println("checkpoint - 7 - something is wrong");
      return null;
    }
  }

Hmm, so you are try-catching already. I might have overlooked it.

Why is it throwing JedisConnectionException, you are returning null for any other exception apart from RuntimeException, right?

Could it be that JedisConnectionException is a RuntimeException?
Let’s check the documentation - doc

Aha!

Hi,

It looks the exception is thrown even before calling the repository service. I am catching the Runtime Exception in the repository service, logging it (System.out.println) and rethrowing it. So if the Runtime Exception was thrown, the log would have shown that.

Thanks,
Raghu

Got it.

But, are you able to see these in your unittesting.log file when the RuntimeException is thrown?

It could be System.out isn’t shown and we need to log it some how differently. Can you try pushing for assessment after making the changes (don’t rethrow any errors)?

I am suggesting that the Exception is thrown from RestaurantRepositoryServiceCacheTest.

Any way I have pushed in my changes. Instead of System.out , I am using a logger there. I am not re-throwing the exception. Also I have added an log.info at the beginning of the method findAllRestaurantsCloseBy - just to see whether that method is getting called.

The assessment still shows the same failed cases. And in the unit-testing log, the logs from the method findAllRestaurantsCloseBy are not present.

Thanks,
Raghu

Hi,
Just checked with Anand. In your initCache() method the JedisPool() constructor isn’t passed the port to connect to. This will be starting the server in the default port and thus can be causing the issue. Can you try passing the redis port parameters as well.

Tried passing the port from the properties file to the JedisPool constructor. Still the assessment fails.

@anand-crio, please take a look

I will try to debug his code sometime today.

If you could help here, I could complete this module.

Tests are passing locally but seems to fail in cloud assessment, have unlocked Mod 7 in the meantime. Please check.