Package org.hivedb

Examples of org.hivedb.Hive


    }
  }

  @Test
  public void testOnDelete() throws Exception{
    Hive hive = getHive();
    ConfigurationReader reader = new ConfigurationReader(Continent.class, WeatherReport.class);
    EntityHiveConfig config = reader.getHiveConfiguration();
    HiveInterceptorDecorator interceptor = new HiveInterceptorDecorator(config, hive);

    WeatherReport report = generateInstance();
    Continent asia = new AsiaticContinent();
    hive.directory().insertPrimaryIndexKey(report.getContinent());
    hive.directory().insertPrimaryIndexKey(asia.getName());
    interceptor.postFlush(Arrays.asList(new Object[]{report,asia}).iterator());

    assertTrue(hive.directory().doesPrimaryIndexKeyExist(report.getContinent()));
    assertTrue(hive.directory().doesResourceIdExist("WeatherReport", report.getReportId()));
    assertTrue(hive.directory().doesResourceIdExist("Temperature", report.getTemperature()));

    assertTrue(hive.directory().doesPrimaryIndexKeyExist(asia.getName()));
    assertTrue(hive.directory().doesSecondaryIndexKeyExist("Continent", "population", asia.getPopulation(), asia.getName()));

    interceptor.onDelete(report, null, null, null, null);
    interceptor.onDelete(asia, null, null, null, null);

    assertFalse(hive.directory().doesResourceIdExist("WeatherReport", report.getReportId()));
    // Referenced entity does not get deleted
    assertTrue(hive.directory().doesResourceIdExist("Temperature", report.getTemperature()));

    assertFalse(hive.directory().doesPrimaryIndexKeyExist(asia.getName()));
    assertFalse(hive.directory().doesSecondaryIndexKeyExist("Continent", "population", asia.getPopulation(), asia.getName()));

  }
View Full Code Here


        dao.save(report);
        return report;
      }
    }, new NumberIterator(INSTANCES));

    Hive hive = getHive();
    // Make sure we saved to > 1 node
    Assert.assertTrue(1 < hive.directory().getNodeIdsOfSecondaryIndexKey("WeatherReport", "regionCode", Atom.getFirstOrThrow(reports).getRegionCode()).size());
    // Make sure all instances are found across nodes
    Assert.assertEquals(INSTANCES, dao.findByProperty("latitude", 1d).size());
  }
View Full Code Here

  }

  @Test
  public void testOnSaveUpdate() throws Exception {
    Hive hive = getHive();
    EntityHiveConfig config = getEntityHiveConfig();
    HiveInterceptorDecorator interceptor = new HiveInterceptorDecorator(config, hive);

    WeatherReport report = generateInstance();
    hive.directory().insertPrimaryIndexKey(report.getContinent());
    interceptor.postFlush(Arrays.asList(new WeatherReport[]{report}).iterator());

    assertTrue(hive.directory().doesPrimaryIndexKeyExist(report.getContinent()));
    assertTrue(hive.directory().doesResourceIdExist("WeatherReport", report.getReportId()));
    assertTrue(hive.directory().doesResourceIdExist("Temperature", report.getTemperature()));

    int oldTemperature = report.getTemperature();
    GeneratedInstanceInterceptor.setProperty(report, "temperature", 72);
    assertFalse(oldTemperature == 72);
    interceptor.postFlush(Arrays.asList(new WeatherReport[]{report}).iterator());
    assertTrue(hive.directory().doesResourceIdExist("Temperature", 72));
  }
View Full Code Here

   * Load two Hive instances, use one to update the hive, and have the other listen for updates
   * from the HiveSyncDaeon.
   */
  @Test
  public void testDaemonSync() throws Exception {
    Hive hive = loadHive();
    Hive passiveSync = loadHive();
    ArrayList<Observer> observers = new ArrayList<Observer>();
    observers.add(passiveSync);
    HiveSyncDaemon daemon = new HiveSyncDaemon(getConnectString(getHiveDatabaseName()), observers);
    daemon.detectChanges();

    hive.addNode(createNode(getHiveDatabaseName()));

    daemon.detectChanges();

//    nodeReport(passiveSync, hive);

    Assert.assertNotNull(passiveSync.getNode(createNode(getHiveDatabaseName()).getName()));
  }
View Full Code Here

public class HiveIndexerTest extends HiveTest {

  // Test for HiveIndexer.insert(final EntityIndexConfiguration config, final Object entity)
  @Test
  public void insertTest() throws Exception {
    Hive hive = getHive();
    HiveIndexer indexer = new HiveIndexer(hive);
    WeatherReport report = generateInstance();
    indexer.insert(getWeatherReportConfig(report), report);
    assertTrue(hive.directory().doesResourceIdExist("WeatherReport", report.getReportId()));
    assertTrue(hive.directory().doesResourceIdExist("Temperature", report.getTemperature()));
    for (WeatherEvent weatherEvent : report.getWeatherEvents())
      assertTrue(hive.directory().doesSecondaryIndexKeyExist("WeatherReport", "weatherEventEventId", weatherEvent.getEventId(), report.getReportId()));
  }
View Full Code Here

    validateSchema(schema, Hive.load(uri(), CachingDataSourceProvider.getInstance()).getNode(nodeName));
  }

  @Test
  public void installASchemaOnAnExistingNode() throws Exception {
    Hive hive = Hive.load(uri(), CachingDataSourceProvider.getInstance());
    String nodeName = "anExistingNode";
    Node node = new Node(nodeName, H2TestCase.TEST_DB, "unecessary", HiveDbDialect.H2);
    hive.addNode(node);
    WeatherSchema weatherSchema = WeatherSchema.getInstance();
    getService().install(weatherSchema.getName(), nodeName);
    validateSchema(weatherSchema, node);
  }
View Full Code Here

    validateSchema(weatherSchema, node);
  }

  @Test
  public void tryToInstallToAReadOnlyHive() throws Exception {
    Hive hive = Hive.load(uri(), CachingDataSourceProvider.getInstance());
    hive.updateHiveStatus(Status.readOnly);

    try {
      getService().install(WeatherSchema.getInstance().getName(), "aNewNode", H2TestCase.TEST_DB, "unecessary for H2", "H2", "na", "na");

      fail("No exception Thrown");
View Full Code Here

  }

  // Test for HiveIndexer.update(EntityIndexConfiguration config, Object entity)
  @Test
  public void updateTest() throws Exception {
    Hive hive = getHive();
    HiveIndexer indexer = new HiveIndexer(hive);
    WeatherReport report = generateInstance();
    Integer oldTemp = report.getTemperature();
    indexer.insert(getWeatherReportConfig(report), report);
    assertWeatherReportResourceIdsOfPrimaryIndexKey("WeatherReport", report);
    assertTrue(hive.directory().doesResourceIdExist("Temperature", report.getTemperature()));
    GeneratedInstanceInterceptor.setProperty(report, "temperature", 32);
    indexer.update(getWeatherReportConfig(report), report);
    assertEquals(report.getContinent(), hive.directory().getPrimaryIndexKeyOfResourceId("Temperature", 32));
  }
View Full Code Here

    assertEquals(report.getContinent(), hive.directory().getPrimaryIndexKeyOfResourceId(resource, report.getReportId()));
  }

  @Test
  public void changePartitionKeyTest() throws Exception {
    Hive hive = getHive();
    HiveIndexer indexer = new HiveIndexer(hive);
    WeatherReport report = generateInstance();
    GeneratedInstanceInterceptor.setProperty(report, "continent", "Asia");
    Integer oldTemp = report.getTemperature();
    indexer.insert(getWeatherReportConfig(report), report);
    assertWeatherReportResourceIdsOfPrimaryIndexKey("WeatherReport", report);
    assertTrue(hive.directory().doesResourceIdExist("Temperature", report.getTemperature()));
    assertEquals("Asia", hive.directory().getPrimaryIndexKeyOfResourceId("WeatherReport", report.getReportId()));

    GeneratedInstanceInterceptor.setProperty(report, "continent", "Europe");
    indexer.update(getWeatherReportConfig(report), report);
    GeneratedInstanceInterceptor.setProperty(report, "temperature", 32);
    indexer.update(getWeatherReportConfig(report), report);

    assertEquals("Europe", hive.directory().getPrimaryIndexKeyOfResourceId("WeatherReport", report.getReportId()));
  }
View Full Code Here

  }

  // Test for HiveIndexer.delete(EntityIndexConfiguration config, Object entity)
  @Test
  public void deleteTest() throws Exception {
    Hive hive = getHive();
    HiveIndexer indexer = new HiveIndexer(hive);
    WeatherReport report = generateInstance();
    indexer.insert(getWeatherReportConfig(report), report);
    assertTrue(hive.directory().doesResourceIdExist("WeatherReport", report.getReportId()));
    assertTrue(hive.directory().doesResourceIdExist("Temperature", report.getTemperature()));
    indexer.delete(getWeatherReportConfig(report), report);
    assertFalse(hive.directory().doesResourceIdExist("WeatherReport", report.getReportId()));
    // Temperature is an entity so it does not get deleted
    assertTrue(hive.directory().doesResourceIdExist("Temperature", report.getTemperature()));
    indexer.delete(getWeatherReportConfig(report), report);
  }
View Full Code Here

TOP

Related Classes of org.hivedb.Hive

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.