@Test public void testLinkNameNotNull() { assertEquals(getNumberOfLinks(), getClient().getLinks().size()); for (MLink link : getClient().getLinks()) { assertNotNull(link.getName()); } MLink link = getClient().createLink("generic-jdbc-connector"); assertNull(link.getName()); assertEquals(getClient().saveLink(link), Status.ERROR); }
@Test public void testGetLink() { MLink testLink = new MLink(123l, null); testLink.setEnabled(true); MLink mConnectionSpy = org.mockito.Mockito.spy(testLink); when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock); when(jdbcRepoMock.findLink(123l)).thenReturn(mConnectionSpy); assertEquals(jobManager.getLink(123l), mConnectionSpy); verify(repositoryManagerMock, times(1)).getRepository(); verify(jdbcRepoMock, times(1)).findLink(123l); }
private Status cloneLink(String linkArg, List<String> args, boolean isInteractive) throws IOException { printlnResource(Constants.RES_CLONE_CLONING_LINK, linkArg); ConsoleReader reader = new ConsoleReader(); MLink connection = client.getLink(linkArg); // Remove persistent id as we're making a clone connection.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT); Status status = Status.OK; ResourceBundle linkConfigBundle = client.getConnectorConfigBundle(connection.getConnectorId()); if (isInteractive) { printlnResource(Constants.RES_PROMPT_UPDATE_LINK_CONFIG); do { // Print error introduction if needed if (!status.canProceed()) { errorIntroduction(); } // Fill in data from user if (!fillLinkWithBundle(reader, connection, linkConfigBundle)) { return null; } status = client.saveLink(connection); } while (!status.canProceed()); } else { LinkDynamicConfigOptions options = new LinkDynamicConfigOptions(); options.prepareOptions(connection); CommandLine line = ConfigOptions.parseOptions(options, 0, args, false); if (fillLink(line, connection)) { status = client.saveLink(connection); if (!status.canProceed()) { printLinkValidationMessages(connection); return null; } } else { printLinkValidationMessages(connection); return null; } } printlnResource( Constants.RES_CLONE_LINK_SUCCESSFUL, status.name(), connection.getPersistenceId()); return status; }
/** * Fill link config based on currently active provider. * * @param link MLink object to fill */ protected void fillRdbmsLinkConfig(MLink link) { MConfigList configs = link.getConnectorLinkConfig(); configs.getStringInput("linkConfig.jdbcDriver").setValue(provider.getJdbcDriver()); configs.getStringInput("linkConfig.connectionString").setValue(provider.getConnectionUrl()); configs.getStringInput("linkConfig.username").setValue(provider.getConnectionUsername()); configs.getStringInput("linkConfig.password").setValue(provider.getConnectionPassword()); }
@Test public void testBasic() throws Exception { createFromFile( "input-0001", "1,'USA','2004-10-23','San Francisco'", "2,'USA','2004-10-24','Sunnyvale'", "3,'Czech Republic','2004-10-25','Brno'", "4,'USA','2004-10-26','Palo Alto'"); // RDBMS link MLink rdbmsLink = getClient().createLink("generic-jdbc-connector"); fillRdbmsLinkConfig(rdbmsLink); saveLink(rdbmsLink); // HDFS link MLink hdfsLink = getClient().createLink("hdfs-connector"); fillHdfsLink(hdfsLink); saveLink(hdfsLink); // Job creation MJob job = getClient().createJob(hdfsLink.getName(), rdbmsLink.getName()); // set hdfs "FROM" config for the job, since the connector test case base class only has // utilities for hdfs! fillHdfsFromConfig(job); // set the rdbms "TO" config here fillRdbmsToConfig(job); // driver config MDriverConfig driverConfig = job.getDriverConfig(); driverConfig.getIntegerInput("throttlingConfig.numExtractors").setValue(3); saveJob(job); executeJob(job); assertEquals(4L, provider.rowCount(getTableName())); assertRowInCities(1, "USA", "2004-10-23", "San Francisco"); assertRowInCities(2, "USA", "2004-10-24", "Sunnyvale"); assertRowInCities(3, "Czech Republic", "2004-10-25", "Brno"); assertRowInCities(4, "USA", "2004-10-26", "Palo Alto"); }
@Test public void testDisabledLink() { MLink testConnection = new MLink(123l, null); testConnection.setPersistenceId(1234); testConnection.setEnabled(false); SqoopException exception = new SqoopException( DriverError.DRIVER_0010, "Connection id: " + testConnection.getPersistenceId()); MLink mConnectionSpy = org.mockito.Mockito.spy(testConnection); when(repositoryManagerMock.getRepository()).thenReturn(jdbcRepoMock); when(jdbcRepoMock.findLink(123l)).thenReturn(mConnectionSpy); try { jobManager.getLink(123l); } catch (SqoopException ex) { assertEquals(ex.getMessage(), exception.getMessage()); verify(repositoryManagerMock, times(1)).getRepository(); verify(jdbcRepoMock, times(1)).findLink(123l); } }
protected void fillKafkaLinkConfig(MLink link) { MConfigList configs = link.getConnectorLinkConfig(); configs.getStringInput("linkConfig.brokerList").setValue(testUtil.getKafkaServerUrl()); configs.getStringInput("linkConfig.zookeeperConnect").setValue(testUtil.getZkUrl()); }
/** * Create link. * * <p>With asserts to make sure that it was created correctly. * * @param link */ protected void saveLink(MLink link) { SqoopUtils.fillObjectName(link); assertEquals(getClient().saveLink(link), Status.OK); assertNotSame(link.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT); }
protected void fillHdfsLink(MLink link) { MConfigList configs = link.getConnectorLinkConfig(); configs.getStringInput("linkConfig.confDir").setValue(getCluster().getConfigurationPath()); }