Package org.hivedb.util.database.test

Examples of org.hivedb.util.database.test.WeatherReport


  private HiveSessionFactoryImpl hiveSessionFactory;

  @Test
  public void shouldSaveEntities() throws Exception {
    DataAccessObject<WeatherReport, Integer> dao = new ErrorCorrectingDataAccessObject<WeatherReport, Integer>(WeatherReport.class, getEntityHiveConfig().getEntityConfig(WeatherReport.class),getHive(), getSessionFactory());
    WeatherReport original = WeatherReportImpl.generate();
    dao.save(original);
    WeatherReport fetched = dao.get(original.getReportId());
    assertEquals(original, fetched);
  }
View Full Code Here


  }

  @Test
  public void shouldSaveAndReIndexIfAnEntityExistsOnTheDataNodeButNotTheDirectory() throws Exception {
    DataAccessObject<WeatherReport, Integer> dao = new ErrorCorrectingDataAccessObject<WeatherReport, Integer>(WeatherReport.class, getEntityHiveConfig().getEntityConfig(WeatherReport.class),getHive(), getSessionFactory());
    WeatherReport report = getPersistentInstance(dao);
    hive.directory().deleteResourceId("WeatherReport", report.getReportId());
    assertFalse(hive.directory().getNodeIdsOfResourceId("WeatherReport", report.getReportId()).size() > 0);
    report.setRegionCode(87654);
    dao.save(report);
    assertTrue(hive.directory().getNodeIdsOfResourceId("WeatherReport", report.getReportId()).size() > 0);
    WeatherReport thawed = dao.get(report.getReportId());
    assertEquals(report, thawed);
  }
View Full Code Here

  }

  @Test
  public void shouldSaveEntitiesWhenThePartitionKeyChanges() throws Exception {
    DataAccessObject<WeatherReport, Integer> dao = new ErrorCorrectingDataAccessObject<WeatherReport, Integer>(WeatherReport.class, getEntityHiveConfig().getEntityConfig(WeatherReport.class),getHive(), getSessionFactory());
    WeatherReport report = getPersistentInstance(dao);
    String oldContinent = report.getContinent();
    String newContinent = report.getContinent().equals("Asia") ? "Australia" : "Asia";
    report.setContinent(newContinent);
    dao.save(report);
    Session oldNodeSession = null;
    Session newNodeSession = null;

    try {
      oldNodeSession = hiveSessionFactory.openSession(oldContinent);
      newNodeSession = hiveSessionFactory.openSession(newContinent);
      if(!hive.directory().getNodeIdsOfPrimaryIndexKey(oldContinent).equals(hive.directory().getNodeIdsOfPrimaryIndexKey(newContinent)))
        assertNull(oldNodeSession.get(WeatherReport.class, report.getReportId()));
      WeatherReport fetched = (WeatherReport) newNodeSession.get(WeatherReport.class, report.getReportId());
      assertNotNull(fetched);
      assertEquals(newContinent, fetched.getContinent());
    } finally {
      if(oldNodeSession != null)
        oldNodeSession.close();
      if(newNodeSession != null)
        newNodeSession.close();
View Full Code Here

  }

  @Test
  public void shouldDeleteRecords() throws Exception {
    DataAccessObject<WeatherReport, Integer> dao = new ErrorCorrectingDataAccessObject<WeatherReport, Integer>(WeatherReport.class, getEntityHiveConfig().getEntityConfig(WeatherReport.class),getHive(), getSessionFactory());
    WeatherReport report = getPersistentInstance(dao);
    assertTrue(dao.exists(report.getReportId()));
    dao.delete(report.getReportId());
    assertFalse(dao.exists(report.getReportId()));
  }
View Full Code Here

 
  @Test
  public void testOpenSessionByPrimaryKey() throws Exception {
    HiveSessionFactoryBuilderImpl factoryBuilder = getHiveSessionFactoryBuilder();
   
    final WeatherReport report = newInstance();
   
    save(factoryBuilder, report);
    assertNotNull(factoryBuilder.getSessionFactory());
    factoryBuilder.openSession(config.getEntityConfig(getGeneratedClass(WeatherReport.class)).getPrimaryIndexKey(report));
  }
View Full Code Here

  @Test
  public void testOpenSessionByResourceId() throws Exception {
    HiveSessionFactoryBuilderImpl factoryBuilder = getHiveSessionFactoryBuilder();
    assertNotNull(factoryBuilder.getSessionFactory());
   
    final WeatherReport report = newInstance();
    save(factoryBuilder, report);
   
    factoryBuilder.openSession("WeatherReport", config.getEntityConfig(getGeneratedClass(WeatherReport.class)).getId(report));
  }
View Full Code Here

 
  @Test
  public void testOpenSessionBySecondaryIndex() throws Exception {
    HiveSessionFactoryBuilderImpl factoryBuilder = getHiveSessionFactoryBuilder();

    final WeatherReport report = newInstance();
    save(factoryBuilder, report);
   
    factoryBuilder.openSession("WeatherReport", "weatherEventEventId", Atom.getFirstOrThrow(report.getWeatherEvents()).getEventId());
  }
View Full Code Here

  }
 
  @Test
  public void testInsert() throws Exception {
    HiveSessionFactoryBuilderImpl factoryBuilder = getHiveSessionFactoryBuilder();
    final WeatherReport report = newInstance();
    for (Node node : getHive().getNodes()) {
      if (! Schemas.tableExists("WEATHER_REPORT", node.getUri())) {
        throw new RuntimeException("Can't find WEATHER_REPORT table on node " + node.getUri());
      }
    }
    save(factoryBuilder, report);
    Hive hive = getHive();
    assertTrue(hive.directory().doesResourceIdExist("WeatherReport", report.getReportId()));
    assertTrue(hive.directory().doesResourceIdExist("Temperature", report.getTemperature()));   
  }
View Full Code Here

  }

  @Test
  public void shouldNotThrowAnExceptionWhenDeletingNonExistentRecords() throws Exception {
    DataAccessObject<WeatherReport, Integer> dao = new ErrorCorrectingDataAccessObject<WeatherReport, Integer>(WeatherReport.class, getEntityHiveConfig().getEntityConfig(WeatherReport.class),getHive(), getSessionFactory());
    WeatherReport report = WeatherReportImpl.generate();
    assertFalse(dao.exists(report.getReportId()));
    dao.delete(report.getReportId());
    assertFalse(dao.exists(report.getReportId()));
  }
View Full Code Here

  }
 
  @Test
  public void testInsertFail() throws Exception {
    HiveSessionFactoryBuilderImpl factoryBuilder = getHiveSessionFactoryBuilder();
    final WeatherReport report = newInstance();
   
    Session session = factoryBuilder.getSessionFactory().openSession();
    SessionCallback callback = new SessionCallback(){
      public void execute(Session session) {
        session.saveOrUpdate(report);
      }};
    for (Node node : getHive().getNodes()) {
      if (! Schemas.tableExists("WEATHER_REPORT", node.getUri())) {
        throw new RuntimeException("Can't find WEATHER_REPORT table on node " + node.getUri());
      }
    }
    doInTransactionAndFailBeforeCommit(callback, session);
   
    Hive hive = getHive();
    assertFalse(hive.directory().doesResourceIdExist("WeatherReport", report.getReportId()));
    assertFalse(hive.directory().doesResourceIdExist("Temperature", report.getTemperature()));   
    assertTrue(factoryBuilder.getDefaultInterceptor().isTransient(report));
  }
View Full Code Here

TOP

Related Classes of org.hivedb.util.database.test.WeatherReport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.