List of usage examples for org.apache.commons.lang StringUtils repeat
public static String repeat(String str, int repeat)
Repeat a String repeat
times to form a new String.
From source file:org.apache.ddlutils.io.TestDataReaderAndWriter.java
/** * Tests the reader & writer behavior when a column name is not a valid tag, * and the column name is shorter than 255 characters and the value is longer. *//*from w w w . java 2s.c o m*/ public void testColumnNameShortAndInvalidAndValueLong() throws Exception { Database model = readModel("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='test'>\n" + " <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='the value' type='VARCHAR' size='50' required='true'/>\n" + " </table>\n" + "</database>"); String testedValue = StringUtils.repeat("Some Text", 40); SqlDynaBean bean = (SqlDynaBean) model.createDynaBeanFor(model.getTable(0)); bean.set("id", new Integer(1)); bean.set("the value", testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column column-name=\"the value\">" + testedValue + "</column>\n" + " </test>\n" + "</data>\n"); }
From source file:org.apache.ddlutils.io.TestDataReaderAndWriter.java
/** * Tests the reader & writer behavior when a column name is a valid tag, * and the column name is longer than 255 characters and the value is shorter. *//*from w ww . j av a 2s .c o m*/ public void testColumnNameLongAndValueShort() throws Exception { String columnName = StringUtils.repeat("value", 100); Database model = readModel("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='test'>\n" + " <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='" + columnName + "' type='VARCHAR' size='50' required='true'/>\n" + " </table>\n" + "</database>"); String testedValue = "Some Text"; SqlDynaBean bean = (SqlDynaBean) model.createDynaBeanFor(model.getTable(0)); bean.set("id", new Integer(1)); bean.set(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column>\n" + " <column-name>" + columnName + "</column-name>\n" + " <column-value>" + testedValue + "</column-value>\n" + " </column>\n" + " </test>\n" + "</data>\n"); }
From source file:org.apache.ddlutils.io.TestDataReaderAndWriter.java
/** * Tests the reader & writer behavior when a column name is a valid tag, * and both the column name and value are longer than 255 characters. *//*w w w. j ava 2 s . c om*/ public void testColumnNameLongAndValueLong() throws Exception { String columnName = StringUtils.repeat("value", 100); Database model = readModel("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='test'>\n" + " <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='" + columnName + "' type='VARCHAR' size='500' required='true'/>\n" + " </table>\n" + "</database>"); String testedValue = StringUtils.repeat("Some Text", 40); SqlDynaBean bean = (SqlDynaBean) model.createDynaBeanFor(model.getTable(0)); bean.set("id", new Integer(1)); bean.set(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column>\n" + " <column-name>" + columnName + "</column-name>\n" + " <column-value>" + testedValue + "</column-value>\n" + " </column>\n" + " </test>\n" + "</data>\n"); }
From source file:org.apache.ddlutils.io.TestDataReaderAndWriter.java
/** * Tests the reader & writer behavior when a column name is a valid tag, * and the column name is longer than 255 characters and the value is shorter. *///from www .j a va 2 s .c o m public void testColumnNameAndValueLong() throws Exception { String columnName = StringUtils.repeat("value", 100); Database model = readModel("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='test'>\n" + " <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='" + columnName + "' type='VARCHAR' size='50' required='true'/>\n" + " </table>\n" + "</database>"); String testedValue = "Some Text"; SqlDynaBean bean = (SqlDynaBean) model.createDynaBeanFor(model.getTable(0)); bean.set("id", new Integer(1)); bean.set(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column>\n" + " <column-name>" + columnName + "</column-name>\n" + " <column-value>" + testedValue + "</column-value>\n" + " </column>\n" + " </test>\n" + "</data>\n"); }
From source file:org.apache.ddlutils.io.TestDataReaderAndWriter.java
/** * Tests the reader & writer behavior when a column name is a valid tag and longer, * than 255 characters, and the value is invalid and shorter than 255 characters. *//*from w w w .j a va 2 s .c o m*/ public void testColumnNameLongAndValueInvalidAndShort() throws Exception { String columnName = StringUtils.repeat("value", 100); Database model = readModel("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='test'>\n" + " <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n" + " <column name='" + columnName + "' type='VARCHAR' size='50' required='true'/>\n" + " </table>\n" + "</database>"); String testedValue = "the\u0000value"; SqlDynaBean bean = (SqlDynaBean) model.createDynaBeanFor(model.getTable(0)); bean.set("id", new Integer(1)); bean.set(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column>\n" + " <column-name>" + columnName + "</column-name>\n" + " <column-value " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(testedValue.getBytes("UTF-8")), "UTF-8") + "</column-value>\n" + " </column>\n" + " </test>\n" + "</data>\n"); }
From source file:org.apache.ddlutils.io.TestDataReaderAndWriter.java
/** * Tests the reader & writer behavior when a column name is not a valid tag, * and the value is invalid, and both are short. *///from w ww. ja v a 2s .com public void testColumnNameAndValueLongAndInvalid() throws Exception { Database model = new Database("test"); Table table = new Table(); Column idColumn = new Column(); Column valueColumn = new Column(); String columnName = StringUtils.repeat("the\u0000name", 100); idColumn.setName("id"); idColumn.setType("INTEGER"); idColumn.setPrimaryKey(true); idColumn.setRequired(true); valueColumn.setName(columnName); valueColumn.setType("VARCHAR"); valueColumn.setSize("50"); valueColumn.setRequired(true); table.setName("test"); table.addColumn(idColumn); table.addColumn(valueColumn); model.addTable(table); SqlDynaBean bean = (SqlDynaBean) model.createDynaBeanFor(model.getTable(0)); String testedValue = StringUtils.repeat("the\u0000value", 40); bean.set("id", new Integer(1)); bean.set(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column>\n" + " <column-name " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(columnName.getBytes("UTF-8")), "UTF-8") + "</column-name>\n" + " <column-value " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(testedValue.getBytes("UTF-8")), "UTF-8") + "</column-value>\n" + " </column>\n" + " </test>\n" + "</data>\n"); }
From source file:org.apache.eagle.app.environment.impl.StormSubmitter.java
/** * Submits a topology to run on the cluster with a progress bar. A topology runs forever or until * explicitly killed./*from ww w . j a va2 s . com*/ * * * @param name the name of the storm. * @param stormConf the topology-specific configuration. See {@link Config}. * @param topology the processing to execute. * @param opts to manipulate the starting of the topology * @throws AlreadyAliveException if a topology with this name is already running * @throws InvalidTopologyException if an invalid topology was submitted */ public static void submitTopologyWithProgressBar(String name, Map stormConf, StormTopology topology, SubmitOptions opts) throws AlreadyAliveException, InvalidTopologyException { // show a progress bar so we know we're not stuck (especially on slow connections) submitTopology(name, stormConf, topology, opts, new StormSubmitter.ProgressListener() { @Override public void onStart(String srcFile, String targetFile, long totalBytes) { System.out.printf("Start uploading file '%s' to '%s' (%d bytes)\n", srcFile, targetFile, totalBytes); } @Override public void onProgress(String srcFile, String targetFile, long bytesUploaded, long totalBytes) { int length = 50; int p = (int) ((length * bytesUploaded) / totalBytes); String progress = StringUtils.repeat("=", p); String todo = StringUtils.repeat(" ", length - p); System.out.printf("\r[%s%s] %d / %d", progress, todo, bytesUploaded, totalBytes); } @Override public void onCompleted(String srcFile, String targetFile, long totalBytes) { System.out.printf("\nFile '%s' uploaded to '%s' (%d bytes)\n", srcFile, targetFile, totalBytes); } }); }
From source file:org.apache.flink.streaming.connectors.kinesis.internals.ShardConsumerTest.java
@Test public void testCorrectNumOfCollectedRecordsAndUpdatedState() { KinesisStreamShard fakeToBeConsumedShard = new KinesisStreamShard("fakeStream", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0)) .withHashKeyRange(new HashKeyRange().withStartingHashKey("0") .withEndingHashKey(new BigInteger(StringUtils.repeat("FF", 16), 16).toString()))); LinkedList<KinesisStreamShardState> subscribedShardsStateUnderTest = new LinkedList<>(); subscribedShardsStateUnderTest//from w w w. ja va 2 s. c o m .add(new KinesisStreamShardState(fakeToBeConsumedShard, new SequenceNumber("fakeStartingState"))); TestableKinesisDataFetcher fetcher = new TestableKinesisDataFetcher(Collections.singletonList("fakeStream"), new Properties(), 10, 2, new AtomicReference<Throwable>(), subscribedShardsStateUnderTest, KinesisDataFetcher.createInitialSubscribedStreamsToLastDiscoveredShardsState( Collections.singletonList("fakeStream")), Mockito.mock(KinesisProxyInterface.class)); new ShardConsumer<>(fetcher, 0, subscribedShardsStateUnderTest.get(0).getKinesisStreamShard(), subscribedShardsStateUnderTest.get(0).getLastProcessedSequenceNum(), FakeKinesisBehavioursFactory.totalNumOfRecordsAfterNumOfGetRecordsCalls(1000, 9)).run(); assertTrue(fetcher.getNumOfElementsCollected() == 1000); assertTrue(subscribedShardsStateUnderTest.get(0).getLastProcessedSequenceNum() .equals(SentinelSequenceNumber.SENTINEL_SHARD_ENDING_SEQUENCE_NUM.get())); }
From source file:org.apache.flink.streaming.connectors.kinesis.internals.ShardConsumerTest.java
@Test public void testCorrectNumOfCollectedRecordsAndUpdatedStateWithUnexpectedExpiredIterator() { KinesisStreamShard fakeToBeConsumedShard = new KinesisStreamShard("fakeStream", new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(0)) .withHashKeyRange(new HashKeyRange().withStartingHashKey("0") .withEndingHashKey(new BigInteger(StringUtils.repeat("FF", 16), 16).toString()))); LinkedList<KinesisStreamShardState> subscribedShardsStateUnderTest = new LinkedList<>(); subscribedShardsStateUnderTest// ww w. j a va2s .c o m .add(new KinesisStreamShardState(fakeToBeConsumedShard, new SequenceNumber("fakeStartingState"))); TestableKinesisDataFetcher fetcher = new TestableKinesisDataFetcher(Collections.singletonList("fakeStream"), new Properties(), 10, 2, new AtomicReference<Throwable>(), subscribedShardsStateUnderTest, KinesisDataFetcher.createInitialSubscribedStreamsToLastDiscoveredShardsState( Collections.singletonList("fakeStream")), Mockito.mock(KinesisProxyInterface.class)); new ShardConsumer<>(fetcher, 0, subscribedShardsStateUnderTest.get(0).getKinesisStreamShard(), subscribedShardsStateUnderTest.get(0).getLastProcessedSequenceNum(), // Get a total of 1000 records with 9 getRecords() calls, // and the 7th getRecords() call will encounter an unexpected expired shard iterator FakeKinesisBehavioursFactory .totalNumOfRecordsAfterNumOfGetRecordsCallsWithUnexpectedExpiredIterator(1000, 9, 7)).run(); assertTrue(fetcher.getNumOfElementsCollected() == 1000); assertTrue(subscribedShardsStateUnderTest.get(0).getLastProcessedSequenceNum() .equals(SentinelSequenceNumber.SENTINEL_SHARD_ENDING_SEQUENCE_NUM.get())); }
From source file:org.apache.flink.streaming.connectors.kinesis.internals.ShardConsumerThreadTest.java
@Test public void testAllRecordsFetchedFromKinesisAreCorrectlyCollected() { int totalRecordCount = 500; KinesisStreamShard assignedShardUnderTest = new KinesisStreamShard("fake-stream-name", new Shard().withShardId("fake-shard-id").withAdjacentParentShardId(null).withParentShardId(null) .withHashKeyRange(new HashKeyRange().withStartingHashKey("0") .withEndingHashKey(StringUtils.repeat("FF", 16)))); // ------------------------------------------------------------------------------------------ // the part below prepares the behaviour of the mocked KinesisProxy for getting the inital shard iterator, // followed by consecutive getRecords() calls until total of 500 records fetched // ------------------------------------------------------------------------------------------ KinesisProxy kinesisProxyMock = Mockito.mock(KinesisProxy.class); Mockito.when(kinesisProxyMock.getShardIterator(Matchers.any(KinesisStreamShard.class), Matchers.anyString(), Matchers.anyString())).thenReturn("fake-initial-shard-itr"); // 1st getRecords() returns 100 records GetRecordsResult getRecordsResultFirst = new GetRecordsResult() .withRecords(generateFakeListOfRecordsFromToIncluding(0, 99)) .withNextShardIterator("fake-1st-shard-itr"); // 2nd getRecords() returns 90 records GetRecordsResult getRecordsResultSecond = new GetRecordsResult() .withRecords(generateFakeListOfRecordsFromToIncluding(100, 189)) .withNextShardIterator("fake-2nd-shard-itr"); // 3rd getRecords() returns 78 records GetRecordsResult getRecordsResultThird = new GetRecordsResult() .withRecords(generateFakeListOfRecordsFromToIncluding(190, 267)) .withNextShardIterator("fake-3rd-shard-itr"); // 4th getRecords() returns 100 records GetRecordsResult getRecordsResultFourth = new GetRecordsResult() .withRecords(generateFakeListOfRecordsFromToIncluding(268, 367)) .withNextShardIterator("fake-4th-shard-itr"); GetRecordsResult getRecordsResultFifth = new GetRecordsResult() .withRecords(generateFakeListOfRecordsFromToIncluding(368, 459)) .withNextShardIterator("fake-5th-shard-itr"); GetRecordsResult getRecordsResultFinal = new GetRecordsResult() .withRecords(generateFakeListOfRecordsFromToIncluding(460, 499)).withNextShardIterator(null); Mockito.when(kinesisProxyMock.getRecords(Matchers.anyString(), Matchers.anyInt())) .thenReturn(getRecordsResultFirst).thenReturn(getRecordsResultSecond) .thenReturn(getRecordsResultThird).thenReturn(getRecordsResultFourth) .thenReturn(getRecordsResultFifth).thenReturn(getRecordsResultFinal); // assuming that all fetched records are not aggregated, // so we are mocking the static deaggregateRecords() to return the original list of records PowerMockito.mockStatic(ShardConsumerThread.class); PowerMockito/* w w w . j a va 2 s.co m*/ .when(ShardConsumerThread.deaggregateRecords(Matchers.anyListOf(Record.class), Matchers.anyString(), Matchers.anyString())) .thenReturn(convertRecordsToUserRecords(getRecordsResultFirst.getRecords())) .thenReturn(convertRecordsToUserRecords(getRecordsResultSecond.getRecords())) .thenReturn(convertRecordsToUserRecords(getRecordsResultThird.getRecords())) .thenReturn(convertRecordsToUserRecords(getRecordsResultFourth.getRecords())) .thenReturn(convertRecordsToUserRecords(getRecordsResultFifth.getRecords())) .thenReturn(convertRecordsToUserRecords(getRecordsResultFinal.getRecords())); // ------------------------------------------------------------------------------------------ Properties testConsumerConfig = new Properties(); HashMap<KinesisStreamShard, SequenceNumber> seqNumState = new HashMap<>(); DummySourceContext dummySourceContext = new DummySourceContext(); ShardConsumerThread dummyShardConsumerThread = getDummyShardConsumerThreadWithMockedKinesisProxy( dummySourceContext, kinesisProxyMock, Mockito.mock(KinesisDataFetcher.class), testConsumerConfig, assignedShardUnderTest, new SequenceNumber("fake-last-seq-num"), seqNumState); dummyShardConsumerThread.run(); // the final sequence number state for the assigned shard to this consumer thread // should store SENTINEL_SHARD_ENDING_SEQUENCE_NUMBER since the final nextShardItr should be null assertEquals(SentinelSequenceNumber.SENTINEL_SHARD_ENDING_SEQUENCE_NUM.get(), seqNumState.get(assignedShardUnderTest)); // the number of elements collected should equal the number of records generated by mocked KinesisProxy assertEquals(totalRecordCount, dummySourceContext.getNumOfElementsCollected()); }