code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
private void createCompressedWriter() throws Exception { PowerMockito.mockStatic(FileUtil.class); PowerMockito.mockStatic(ReflectionUtil.class); FileWriter writer = Mockito.mock(FileWriter.class); Mockito.when( ReflectionUtil.createFileWriter( Mockito.any(String.class), Mockito.any(LogFilePath.class), Mockito.any(CompressionCodec.class), Mockito.any(SecorConfig.class) )) .thenReturn(writer); Mockito.when(writer.getLength()).thenReturn(123L); FileWriter createdWriter = mRegistry.getOrCreateWriter( mLogFilePathGz, new GzipCodec()); assertTrue(createdWriter == writer); }
FileRegistryTest tests the file registry logic. @author Pawel Garbacki (pawel@pinterest.com)
createCompressedWriter
java
pinterest/secor
src/test/java/com/pinterest/secor/common/FileRegistryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/FileRegistryTest.java
Apache-2.0
public void testGetOrCreateWriterCompressed() throws Exception { createCompressedWriter(); mRegistry.getOrCreateWriter(mLogFilePathGz, new GzipCodec()); // Verify that the method has been called exactly once (the default). PowerMockito.verifyStatic(FileUtil.class); FileUtil.delete(PATH_GZ); PowerMockito.verifyStatic(FileUtil.class); FileUtil.delete(CRC_PATH); PowerMockito.verifyStatic(ReflectionUtil.class); ReflectionUtil.createFileWriter(Mockito.any(String.class), Mockito.any(LogFilePath.class), Mockito.any(CompressionCodec.class), Mockito.any(SecorConfig.class) ); TopicPartition topicPartition = new TopicPartition("some_topic", 0); Collection<TopicPartition> topicPartitions = mRegistry .getTopicPartitions(); assertEquals(1, topicPartitions.size()); assertTrue(topicPartitions.contains(topicPartition)); Collection<LogFilePath> logFilePaths = mRegistry .getPaths(topicPartition); assertEquals(1, logFilePaths.size()); assertTrue(logFilePaths.contains(mLogFilePath)); }
FileRegistryTest tests the file registry logic. @author Pawel Garbacki (pawel@pinterest.com)
testGetOrCreateWriterCompressed
java
pinterest/secor
src/test/java/com/pinterest/secor/common/FileRegistryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/FileRegistryTest.java
Apache-2.0
public void testDeletePath() throws Exception { createWriter(); PowerMockito.mockStatic(FileUtil.class); mRegistry.deletePath(mLogFilePath); PowerMockito.verifyStatic(FileUtil.class); FileUtil.delete(PATH); PowerMockito.verifyStatic(FileUtil.class); FileUtil.delete(CRC_PATH); assertTrue(mRegistry.getPaths(mTopicPartition).isEmpty()); assertTrue(mRegistry.getTopicPartitions().isEmpty()); }
FileRegistryTest tests the file registry logic. @author Pawel Garbacki (pawel@pinterest.com)
testDeletePath
java
pinterest/secor
src/test/java/com/pinterest/secor/common/FileRegistryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/FileRegistryTest.java
Apache-2.0
public void testDeleteTopicPartition() throws Exception { createWriter(); PowerMockito.mockStatic(FileUtil.class); mRegistry.deleteTopicPartition(mTopicPartition); PowerMockito.verifyStatic(FileUtil.class); FileUtil.delete(PATH); PowerMockito.verifyStatic(FileUtil.class); FileUtil.delete(CRC_PATH); assertTrue(mRegistry.getTopicPartitions().isEmpty()); assertTrue(mRegistry.getPaths(mTopicPartition).isEmpty()); }
FileRegistryTest tests the file registry logic. @author Pawel Garbacki (pawel@pinterest.com)
testDeleteTopicPartition
java
pinterest/secor
src/test/java/com/pinterest/secor/common/FileRegistryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/FileRegistryTest.java
Apache-2.0
public void testGetSize() throws Exception { createWriter(); assertEquals(123L, mRegistry.getSize(mTopicPartition)); }
FileRegistryTest tests the file registry logic. @author Pawel Garbacki (pawel@pinterest.com)
testGetSize
java
pinterest/secor
src/test/java/com/pinterest/secor/common/FileRegistryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/FileRegistryTest.java
Apache-2.0
public void testGetModificationAgeSec() throws Exception { PowerMockito.mockStatic(System.class); PowerMockito.when(System.currentTimeMillis()).thenReturn(10000L) .thenReturn(100000L); createWriter(); assertEquals(90, mRegistry.getModificationAgeSec(mTopicPartition)); }
FileRegistryTest tests the file registry logic. @author Pawel Garbacki (pawel@pinterest.com)
testGetModificationAgeSec
java
pinterest/secor
src/test/java/com/pinterest/secor/common/FileRegistryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/FileRegistryTest.java
Apache-2.0
@Override protected void setUp() throws Exception { super.setUp(); mLogFilePath = new LogFilePath(PREFIX, TOPIC, PARTITIONS, GENERATION, KAFKA_PARTITION, LAST_COMMITTED_OFFSET, ""); timestamp = System.currentTimeMillis(); }
LogFileTest tests the logic operating on lof file paths. @author Pawel Garbacki (pawel@pinterest.com)
setUp
java
pinterest/secor
src/test/java/com/pinterest/secor/common/LogFilePathTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/LogFilePathTest.java
Apache-2.0
public void testConstructFromMessage() throws Exception { ParsedMessage message = new ParsedMessage(TOPIC, KAFKA_PARTITION, 1000, null, "some_payload".getBytes(), PARTITIONS, timestamp, null); LogFilePath logFilePath = new LogFilePath(PREFIX, GENERATION, LAST_COMMITTED_OFFSET, message, ""); assertEquals(PATH, logFilePath.getLogFilePath()); }
LogFileTest tests the logic operating on lof file paths. @author Pawel Garbacki (pawel@pinterest.com)
testConstructFromMessage
java
pinterest/secor
src/test/java/com/pinterest/secor/common/LogFilePathTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/LogFilePathTest.java
Apache-2.0
public void testConstructFromPath() throws Exception { LogFilePath logFilePath = new LogFilePath("/some_parent_dir", PATH); assertEquals(PATH, logFilePath.getLogFilePath()); assertEquals(TOPIC, logFilePath.getTopic()); assertTrue(Arrays.equals(PARTITIONS, logFilePath.getPartitions())); assertEquals(GENERATION, logFilePath.getGeneration()); assertEquals(KAFKA_PARTITION, logFilePath.getKafkaPartition()); assertEquals(LAST_COMMITTED_OFFSET, logFilePath.getOffset()); }
LogFileTest tests the logic operating on lof file paths. @author Pawel Garbacki (pawel@pinterest.com)
testConstructFromPath
java
pinterest/secor
src/test/java/com/pinterest/secor/common/LogFilePathTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/LogFilePathTest.java
Apache-2.0
public void testGetters() throws Exception { assertEquals(TOPIC, mLogFilePath.getTopic()); assertTrue(Arrays.equals(PARTITIONS, mLogFilePath.getPartitions())); assertEquals(GENERATION, mLogFilePath.getGeneration()); assertEquals(KAFKA_PARTITION, mLogFilePath.getKafkaPartition()); assertEquals(LAST_COMMITTED_OFFSET, mLogFilePath.getOffset()); }
LogFileTest tests the logic operating on lof file paths. @author Pawel Garbacki (pawel@pinterest.com)
testGetters
java
pinterest/secor
src/test/java/com/pinterest/secor/common/LogFilePathTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/LogFilePathTest.java
Apache-2.0
public void testGetLogFilePath() throws Exception { assertEquals(PATH, mLogFilePath.getLogFilePath()); }
LogFileTest tests the logic operating on lof file paths. @author Pawel Garbacki (pawel@pinterest.com)
testGetLogFilePath
java
pinterest/secor
src/test/java/com/pinterest/secor/common/LogFilePathTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/LogFilePathTest.java
Apache-2.0
public void testGetLogFileCrcPath() throws Exception { assertEquals(CRC_PATH, mLogFilePath.getLogFileCrcPath()); }
LogFileTest tests the logic operating on lof file paths. @author Pawel Garbacki (pawel@pinterest.com)
testGetLogFileCrcPath
java
pinterest/secor
src/test/java/com/pinterest/secor/common/LogFilePathTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/common/LogFilePathTest.java
Apache-2.0
@Override public void setUp() throws Exception { super.setUp(); mLogFilePath = new LogFilePath("/some_parent_dir", PATH); mLogFilePathGz = new LogFilePath("/some_parent_dir", PATH_GZ); }
Test the file readers and writers @author Praveen Murugesan (praveen@uber.com)
setUp
java
pinterest/secor
src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
Apache-2.0
private void setupSequenceFileReaderConfig() { PropertiesConfiguration properties = new PropertiesConfiguration(); properties.addProperty("secor.file.reader.writer.factory", "com.pinterest.secor.io.impl.SequenceFileReaderWriterFactory"); mConfig = new SecorConfig(properties); }
Test the file readers and writers @author Praveen Murugesan (praveen@uber.com)
setupSequenceFileReaderConfig
java
pinterest/secor
src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
Apache-2.0
private void setupDelimitedTextFileWriterConfig() { PropertiesConfiguration properties = new PropertiesConfiguration(); properties.addProperty("secor.file.reader.writer.factory", "com.pinterest.secor.io.impl.DelimitedTextFileReaderWriterFactory"); mConfig = new SecorConfig(properties); }
Test the file readers and writers @author Praveen Murugesan (praveen@uber.com)
setupDelimitedTextFileWriterConfig
java
pinterest/secor
src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
Apache-2.0
private void mockDelimitedTextFileWriter(boolean isCompressed) throws Exception { Path fsPath = (!isCompressed) ? new Path(PATH) : new Path(PATH_GZ); GzipCodec codec = PowerMockito.mock(GzipCodec.class); PowerMockito.whenNew(GzipCodec.class).withNoArguments() .thenReturn(codec); FSDataInputStream fileInputStream = Mockito .mock(FSDataInputStream.class); FSDataOutputStream fileOutputStream = Mockito .mock(FSDataOutputStream.class); PowerMockito.stub(PowerMockito.method(FileSystem.class, "open", Path.class)).toReturn(fileInputStream); PowerMockito.stub(PowerMockito.method(FileSystem.class, "create", Path.class)).toReturn(fileOutputStream); CompressionInputStream inputStream = Mockito .mock(CompressionInputStream.class); CompressionOutputStream outputStream = Mockito .mock(CompressionOutputStream.class); Mockito.when(codec.createInputStream(Mockito.any(InputStream.class))) .thenReturn(inputStream); Mockito.when(codec.createOutputStream(Mockito.any(OutputStream.class))) .thenReturn(outputStream); }
Test the file readers and writers @author Praveen Murugesan (praveen@uber.com)
mockDelimitedTextFileWriter
java
pinterest/secor
src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
Apache-2.0
private void mockSequenceFileWriter(boolean isCompressed) throws Exception { /* We have issues on mockito/javassist with FileSystem.class on JDK 9 Caused by: java.lang.IllegalStateException: Failed to transform class with name org.apache.hadoop.fs.FileSystem$Cache. Reason: org.apache.hadoop.fs.FileSystem$Cache$Key class is frozen PowerMockito.mockStatic(FileSystem.class); FileSystem fs = Mockito.mock(FileSystem.class); Mockito.when( FileSystem.get(Mockito.any(URI.class), Mockito.any(Configuration.class))).thenReturn(fs); */ Path fsPath = (!isCompressed) ? new Path(PATH) : new Path(PATH_GZ); SequenceFile.Reader reader = PowerMockito .mock(SequenceFile.Reader.class); PowerMockito .whenNew(SequenceFile.Reader.class) .withParameterTypes(FileSystem.class, Path.class, Configuration.class) .withArguments(Mockito.any(FileSystem.class), Mockito.eq(fsPath), Mockito.any(Configuration.class)).thenReturn(reader); Mockito.<Class<?>>when(reader.getKeyClass()).thenReturn( (Class<?>) LongWritable.class); Mockito.<Class<?>>when(reader.getValueClass()).thenReturn( (Class<?>) BytesWritable.class); if (!isCompressed) { PowerMockito.mockStatic(SequenceFile.class); SequenceFile.Writer writer = Mockito .mock(SequenceFile.Writer.class); Mockito.when( SequenceFile.createWriter(Mockito.any(FileSystem.class), Mockito.any(Configuration.class), Mockito.eq(fsPath), Mockito.eq(LongWritable.class), Mockito.eq(BytesWritable.class))) .thenReturn(writer); Mockito.when(writer.getLength()).thenReturn(123L); } else { PowerMockito.mockStatic(SequenceFile.class); SequenceFile.Writer writer = Mockito .mock(SequenceFile.Writer.class); Mockito.when( SequenceFile.createWriter(Mockito.any(FileSystem.class), Mockito.any(Configuration.class), Mockito.eq(fsPath), Mockito.eq(LongWritable.class), Mockito.eq(BytesWritable.class), Mockito.eq(SequenceFile.CompressionType.BLOCK), Mockito.any(GzipCodec.class))).thenReturn(writer); Mockito.when(writer.getLength()).thenReturn(12L); } }
Test the file readers and writers @author Praveen Murugesan (praveen@uber.com)
mockSequenceFileWriter
java
pinterest/secor
src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
Apache-2.0
public void testSequenceFileReader() throws Exception { setupSequenceFileReaderConfig(); mockSequenceFileWriter(false); ReflectionUtil.createFileReader(mConfig.getFileReaderWriterFactory(), mLogFilePath, null, mConfig); // Verify that the method has been called exactly once (the default). // PowerMockito.verifyStatic(FileSystem.class); // FileSystem.get(Mockito.any(URI.class), Mockito.any(Configuration.class)); mockSequenceFileWriter(true); ReflectionUtil.createFileWriter(mConfig.getFileReaderWriterFactory(), mLogFilePathGz, new GzipCodec(), mConfig); // Verify that the method has been called exactly once (the default). // PowerMockito.verifyStatic(FileSystem.class); // FileSystem.get(Mockito.any(URI.class), Mockito.any(Configuration.class)); }
Test the file readers and writers @author Praveen Murugesan (praveen@uber.com)
testSequenceFileReader
java
pinterest/secor
src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
Apache-2.0
public void testSequenceFileWriter() throws Exception { setupSequenceFileReaderConfig(); mockSequenceFileWriter(false); FileWriter writer = ReflectionUtil.createFileWriter(mConfig.getFileReaderWriterFactory(), mLogFilePath, null, mConfig); // Verify that the method has been called exactly once (the default). // PowerMockito.verifyStatic(FileSystem.class); // FileSystem.get(Mockito.any(URI.class), Mockito.any(Configuration.class)); assert writer.getLength() == 123L; mockSequenceFileWriter(true); writer = ReflectionUtil.createFileWriter(mConfig.getFileReaderWriterFactory(), mLogFilePathGz, new GzipCodec(), mConfig); // Verify that the method has been called exactly once (the default). // PowerMockito.verifyStatic(FileSystem.class); // FileSystem.get(Mockito.any(URI.class), Mockito.any(Configuration.class)); assert writer.getLength() == 12L; }
Test the file readers and writers @author Praveen Murugesan (praveen@uber.com)
testSequenceFileWriter
java
pinterest/secor
src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
Apache-2.0
public void testDelimitedTextFileWriter() throws Exception { setupDelimitedTextFileWriterConfig(); mockDelimitedTextFileWriter(false); FileWriter writer = (FileWriter) ReflectionUtil .createFileWriter(mConfig.getFileReaderWriterFactory(), mLogFilePath, null, mConfig ); assert writer.getLength() == 0L; mockDelimitedTextFileWriter(true); writer = (FileWriter) ReflectionUtil .createFileWriter(mConfig.getFileReaderWriterFactory(), mLogFilePathGz, new GzipCodec(), mConfig ); assert writer.getLength() == 0L; }
Test the file readers and writers @author Praveen Murugesan (praveen@uber.com)
testDelimitedTextFileWriter
java
pinterest/secor
src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
Apache-2.0
public void testDelimitedTextFileReader() throws Exception { setupDelimitedTextFileWriterConfig(); mockDelimitedTextFileWriter(false); ReflectionUtil.createFileReader(mConfig.getFileReaderWriterFactory(), mLogFilePath, null, mConfig); mockDelimitedTextFileWriter(true); ReflectionUtil.createFileReader(mConfig.getFileReaderWriterFactory(), mLogFilePathGz, new GzipCodec(), mConfig); }
Test the file readers and writers @author Praveen Murugesan (praveen@uber.com)
testDelimitedTextFileReader
java
pinterest/secor
src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/FileReaderWriterFactoryTest.java
Apache-2.0
@Before public void setUp() throws Exception { codec = new GzipCodec(); }
We want to use a pre-determined seed to make the tests deterministic.
setUp
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
private LogFilePath getTempLogFilePath(String topic) { return new LogFilePath(Files.createTempDir().toString(), topic, new String[]{"part-1"}, 0, 1, 0, ".log" ); }
We want to use a pre-determined seed to make the tests deterministic.
getTempLogFilePath
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Test(expected = IllegalArgumentException.class) public void testNoSchema() throws Exception { PropertiesConfiguration properties = new PropertiesConfiguration(); properties.setProperty("secor.orc.schema.provider", DEFAULT_ORC_SCHEMA_PROVIDER); SecorConfig config = new SecorConfig(properties); JsonORCFileReaderWriterFactory factory = new JsonORCFileReaderWriterFactory(config); LogFilePath tempLogFilePath = getTempLogFilePath("test-topic"); // IllegalArgumentException is expected FileWriter fileWriter = factory.BuildFileWriter(tempLogFilePath, codec); }
We want to use a pre-determined seed to make the tests deterministic.
testNoSchema
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
private ReadWriteRecords runTest(String schema, String topic, String... jsonRecords) throws Exception { PropertiesConfiguration properties = new PropertiesConfiguration(); properties.setProperty("secor.orc.schema.provider", DEFAULT_ORC_SCHEMA_PROVIDER); properties.setProperty(String.format("secor.orc.message.schema.%s", topic), schema); SecorConfig config = new SecorConfig(properties); JsonORCFileReaderWriterFactory factory = new JsonORCFileReaderWriterFactory(config); LogFilePath tempLogFilePath = getTempLogFilePath(topic); KeyValue[] written = writeRecords(factory, tempLogFilePath, jsonRecords); KeyValue[] read = readRecords(factory, tempLogFilePath, jsonRecords.length); return new ReadWriteRecords(written, read); }
We want to use a pre-determined seed to make the tests deterministic.
runTest
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
private void runCommonTest(String schema, String topic, String... jsonRecords) throws Exception { ReadWriteRecords records = runTest(schema, topic, jsonRecords); for (int i = 0; i < jsonRecords.length; i++) { // String comparisons make debugging a bit easier, albeit induce greater memory footprint. // For example, byte array comparison yields an error message like: // // java.lang.AssertionError: array lengths differed, expected.length=35 actual.length=32 // // whereas string comparison produces a much more helpful message like: // // org.junit.ComparisonFailure: // Expected :{"mappings":{"key5":0,"key6":1.25}} // Actual :{"mappings":{"key5":0,"key6":1}} // // The original assertion code was: // // assertArrayEquals(written[i].getValue(), read[i].getValue()) // assertEquals(new String(records.written[i].getValue()), new String(records.read[i].getValue())); } }
We want to use a pre-determined seed to make the tests deterministic.
runCommonTest
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
private KeyValue[] writeRecords(JsonORCFileReaderWriterFactory factory, LogFilePath tempLogFilePath, String... jsonRecords) throws Exception { FileWriter fileWriter = factory.BuildFileWriter(tempLogFilePath, codec); KeyValue[] keyValues = new KeyValue[jsonRecords.length]; for (int offset = 0; offset < jsonRecords.length; offset++) { String jsonRecord = jsonRecords[offset]; keyValues[offset] = new KeyValue(offset, jsonRecord.getBytes()); fileWriter.write(keyValues[offset]); } fileWriter.close(); return keyValues; }
We want to use a pre-determined seed to make the tests deterministic.
writeRecords
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
private KeyValue[] readRecords(JsonORCFileReaderWriterFactory factory, LogFilePath tempLogFilePath, int count) throws Exception { FileReader fileReader = factory.BuildFileReader(tempLogFilePath, codec); KeyValue[] keyValues = new KeyValue[count]; for (int offset = 0; offset < count; offset++) { keyValues[offset] = fileReader.next(); } fileReader.close(); return keyValues; }
We want to use a pre-determined seed to make the tests deterministic.
readRecords
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Test public void testMapOfStringToString() throws Exception { runCommonTest( "struct<mappings:map<string\\,string>>", "string-to-string", "{\"mappings\":{\"key1\":\"value1\",\"key2\":\"value2\"}}" ); }
We want to use a pre-determined seed to make the tests deterministic.
testMapOfStringToString
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Test public void testMapOfStringToInteger() throws Exception { runCommonTest( "struct<mappings:map<string\\,int>>", "string-to-integer", "{\"mappings\":{\"key1\":1,\"key2\":-2}}", "{\"mappings\":{\"key3\":1523,\"key4\":3451325}}", "{\"mappings\":{\"key5\":0,\"key6\":-8382}}" ); }
We want to use a pre-determined seed to make the tests deterministic.
testMapOfStringToInteger
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Test public void testMultipleMaps() throws Exception { runCommonTest( "struct<f1:map<string\\,int>\\,f2:map<string\\,string>>", "multiple-maps", "{\"f1\":{\"k1\":0,\"k2\":1234},\"f2\":{\"k3\":\"test\"}}" ); }
We want to use a pre-determined seed to make the tests deterministic.
testMultipleMaps
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Test public void testJsonORCReadWriteRoundTrip() throws Exception { runCommonTest( "struct<firstname:string\\,age:int\\,test:map<string\\,string>>", "round-trip", "{\"firstname\":\"Jason\",\"age\":48,\"test\":{\"k1\":\"v1\",\"k2\":\"v2\"}}", "{\"firstname\":\"Christina\",\"age\":37,\"test\":{\"k3\":\"v3\"}}" ); }
We want to use a pre-determined seed to make the tests deterministic.
testJsonORCReadWriteRoundTrip
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
private JsonObject makeJsonObject(int row, int keysetSize) { JsonObject obj = new JsonObject(); JsonObject kvs = new JsonObject(); for (int i = 0; i < keysetSize; i++) { String key = String.format("key-%d-%d", row, i); int value = random.nextInt(); kvs.addProperty(key, value); } obj.add("kvs", kvs); return obj; }
Generates a JsonObject of a specified keyset size.
makeJsonObject
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Test public void testWithLargeKeySet() throws Exception { int rowCount = 100; String[] jsonObjects = new String[rowCount]; for (int i = 0; i < rowCount; i++) { int keyCount = random.nextInt(5000) + 1; jsonObjects[i] = makeJsonObject(i, keyCount).toString(); } runCommonTest( "struct<kvs:map<string\\,int>>", "large-key-set", jsonObjects ); }
Generates a JsonObject of a specified keyset size.
testWithLargeKeySet
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Test(expected = IllegalArgumentException.class) public void testWithNonStringKeys() throws Exception { runCommonTest( "struct<kvs:map<int\\,int>>", "non-string-keys", "{0:{1:2,3:4}}" ); }
Generates a JsonObject of a specified keyset size.
testWithNonStringKeys
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Test public void testUnionType() throws Exception { runCommonTest( "struct<values:uniontype<int\\,string>>", "union-type", "{\"values\":\"stringvalue\"}", "{\"values\":1234}", "{\"values\":null}" ); }
Generates a JsonObject of a specified keyset size.
testUnionType
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Test(expected = UnsupportedOperationException.class) public void testUnionTypeWithNonPrimitive() throws Exception { runCommonTest( "struct<v1:uniontype<int\\,struct<v2:string\\,v3:bigint>>>", "union-type-with-non-primitive", "{\"v1\":1234}", "{\"v1\":{\"v2\":null,\"v3\":1048576}}" ); }
Generates a JsonObject of a specified keyset size.
testUnionTypeWithNonPrimitive
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Test public void testReadListOfObject() throws Exception { ReadWriteRecords records = runTest( "struct<name:string\\,age:int>", "list-of-objects", "[{\"name\":\"Jon Smith\",\"age\":99}]" ); assertEquals(1, records.read.length); assertEquals(1, records.written.length); assertEquals("[{\"name\":\"Jon Smith\",\"age\":99}]", new String(records.written[0].getValue())); assertEquals("{\"name\":\"Jon Smith\",\"age\":99}", new String(records.read[0].getValue())); }
Generates a JsonObject of a specified keyset size.
testReadListOfObject
java
pinterest/secor
src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/io/impl/JsonORCFileReaderWriterFactoryTest.java
Apache-2.0
@Override protected FileReader createReader(LogFilePath srcPath, CompressionCodec codec) { return mReader; }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
createReader
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
public FileReader getReader() { return mReader; }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
getReader
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
@Override public void setUp() throws Exception { super.setUp(); mTopicPartition = new TopicPartition("some_topic", 0); mLogFilePath = new LogFilePath("/some_parent_dir", "/some_parent_dir/some_topic/some_partition/some_other_partition/" + "10_0_00000000000000000010"); mLogFilePathWithExtension = new LogFilePath("/some_parent_dir", "/some_parent_dir/some_topic/some_partition/some_other_partition/" + "10_0_00000000000000000010.snappy.parquet"); mConfig = Mockito.mock(SecorConfig.class); Mockito.when(mConfig.getLocalPath()).thenReturn("/some_parent_dir"); Mockito.when(mConfig.getMaxFileSizeBytes()).thenReturn(10L); Mockito.when(mConfig.getZookeeperPath()).thenReturn("/"); Mockito.when(mConfig.getOffsetsStorage()).thenReturn(SecorConstants.KAFKA_OFFSETS_STORAGE_ZK); mOffsetTracker = Mockito.mock(OffsetTracker.class); mFileRegistry = Mockito.mock(FileRegistry.class); Mockito.when(mFileRegistry.getSize(mTopicPartition)).thenReturn(100L); HashSet<TopicPartition> topicPartitions = new HashSet<TopicPartition>(); topicPartitions.add(mTopicPartition); Mockito.when(mFileRegistry.getTopicPartitions()).thenReturn( topicPartitions); mUploadManager = new HadoopS3UploadManager(mConfig); mZookeeperConnector = Mockito.mock(ZookeeperConnector.class); mUploader = new TestUploader(mConfig, mOffsetTracker, mFileRegistry, mUploadManager, messageReader, mZookeeperConnector); }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
setUp
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
public void testUploadAtTime() throws Exception { final int minuteUploadMark = 1; PowerMockito.mockStatic(DateTime.class); PowerMockito.when(DateTime.now()).thenReturn(new DateTime(2016,7,27,0,minuteUploadMark,0)); Mockito.when(mConfig.getUploadMinuteMark()).thenReturn(minuteUploadMark); mockS3Configs(); HashSet<LogFilePath> logFilePaths = new HashSet<LogFilePath>(); logFilePaths.add(mLogFilePath); Mockito.when(mFileRegistry.getPaths(mTopicPartition)).thenReturn( logFilePaths); PowerMockito.mockStatic(FileUtil.class); Mockito.when(FileUtil.getPrefix("some_topic", mConfig)). thenReturn("s3a://some_bucket/some_s3_parent_dir"); mUploader.applyPolicy(false); final String lockPath = "/secor/locks/some_topic/0"; Mockito.verify(mZookeeperConnector).lock(lockPath); PowerMockito.verifyStatic(FileUtil.class); FileUtil.moveToCloud( "/some_parent_dir/some_topic/some_partition/some_other_partition/" + "10_0_00000000000000000010", "s3a://some_bucket/some_s3_parent_dir/some_topic/some_partition/" + "some_other_partition/10_0_00000000000000000010"); Mockito.verify(mFileRegistry).deleteTopicPartition(mTopicPartition); Mockito.verify(mZookeeperConnector).setCommittedOffsetCount( mTopicPartition, 1L); Mockito.verify(mOffsetTracker).setCommittedOffsetCount(mTopicPartition, 1L); Mockito.verify(mZookeeperConnector).unlock(lockPath); }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
testUploadAtTime
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
public void testUploadWhenManyFiles() throws Exception { Mockito.when(mConfig.getMaxActiveFiles()).thenReturn(0); mockS3Configs(); HashSet<LogFilePath> logFilePaths = new HashSet<LogFilePath>(); logFilePaths.add(mLogFilePath); Mockito.when(mFileRegistry.getActiveFileCount()).thenReturn(1); // Hard mock other upload conditions for false Mockito.when(mFileRegistry.getModificationAgeSec(mTopicPartition)).thenReturn(-1L); Mockito.when(mFileRegistry.getSize(mTopicPartition)).thenReturn(-1L); Mockito.when(mFileRegistry.getPaths(mTopicPartition)).thenReturn( logFilePaths); PowerMockito.mockStatic(FileUtil.class); Mockito.when(FileUtil.getPrefix("some_topic", mConfig)). thenReturn("s3a://some_bucket/some_s3_parent_dir"); mUploader.applyPolicy(false); final String lockPath = "/secor/locks/some_topic/0"; Mockito.verify(mZookeeperConnector).lock(lockPath); PowerMockito.verifyStatic(FileUtil.class); FileUtil.moveToCloud( "/some_parent_dir/some_topic/some_partition/some_other_partition/" + "10_0_00000000000000000010", "s3a://some_bucket/some_s3_parent_dir/some_topic/some_partition/" + "some_other_partition/10_0_00000000000000000010"); Mockito.verify(mFileRegistry).deleteTopicPartition(mTopicPartition); Mockito.verify(mZookeeperConnector).setCommittedOffsetCount( mTopicPartition, 1L); Mockito.verify(mOffsetTracker).setCommittedOffsetCount(mTopicPartition, 1L); Mockito.verify(mZookeeperConnector).unlock(lockPath); }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
testUploadWhenManyFiles
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
public void testNoUploadWhenManyFiles() throws Exception { Mockito.when(mConfig.getMaxActiveFiles()).thenReturn(10); mockS3Configs(); HashSet<LogFilePath> logFilePaths = new HashSet<LogFilePath>(); logFilePaths.add(mLogFilePath); Mockito.when(mFileRegistry.getActiveFileCount()).thenReturn(1); // Hard mock other upload conditions for false Mockito.when(mFileRegistry.getModificationAgeSec(mTopicPartition)).thenReturn(-1L); Mockito.when(mFileRegistry.getSize(mTopicPartition)).thenReturn(-1L); Mockito.when(mFileRegistry.getPaths(mTopicPartition)).thenReturn( logFilePaths); mUploader.applyPolicy(false); // Nothing happens }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
testNoUploadWhenManyFiles
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
public void testUploadFiles() throws Exception { Mockito.when( mZookeeperConnector.getCommittedOffsetCount(mTopicPartition)) .thenReturn(11L); Mockito.when( mOffsetTracker.setCommittedOffsetCount(mTopicPartition, 11L)) .thenReturn(11L); Mockito.when( mOffsetTracker.setCommittedOffsetCount(mTopicPartition, 21L)) .thenReturn(11L); Mockito.when(mOffsetTracker.getLastSeenOffset(mTopicPartition)) .thenReturn(20L); Mockito.when( mOffsetTracker.getTrueCommittedOffsetCount(mTopicPartition)) .thenReturn(11L); mockS3Configs(); HashSet<LogFilePath> logFilePaths = new HashSet<LogFilePath>(); logFilePaths.add(mLogFilePath); Mockito.when(mFileRegistry.getPaths(mTopicPartition)).thenReturn( logFilePaths); PowerMockito.mockStatic(FileUtil.class); Mockito.when(FileUtil.getPrefix("some_topic", mConfig)). thenReturn("s3a://some_bucket/some_s3_parent_dir"); mUploader.applyPolicy(false); final String lockPath = "/secor/locks/some_topic/0"; Mockito.verify(mZookeeperConnector).lock(lockPath); PowerMockito.verifyStatic(FileUtil.class); FileUtil.moveToCloud( "/some_parent_dir/some_topic/some_partition/some_other_partition/" + "10_0_00000000000000000010", "s3a://some_bucket/some_s3_parent_dir/some_topic/some_partition/" + "some_other_partition/10_0_00000000000000000010"); Mockito.verify(mFileRegistry).deleteTopicPartition(mTopicPartition); Mockito.verify(mZookeeperConnector).setCommittedOffsetCount( mTopicPartition, 21L); Mockito.verify(mOffsetTracker).setCommittedOffsetCount(mTopicPartition, 21L); Mockito.verify(mZookeeperConnector).unlock(lockPath); }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
testUploadFiles
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
public void testDeleteTopicPartition() throws Exception { Mockito.when( mZookeeperConnector.getCommittedOffsetCount(mTopicPartition)) .thenReturn(31L); Mockito.when( mOffsetTracker.setCommittedOffsetCount(mTopicPartition, 30L)) .thenReturn(11L); Mockito.when(mOffsetTracker.getLastSeenOffset(mTopicPartition)) .thenReturn(20L); mUploader.applyPolicy(false); Mockito.verify(mFileRegistry).deleteTopicPartition(mTopicPartition); }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
testDeleteTopicPartition
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
public void testTrimFiles() throws Exception { Mockito.when( mZookeeperConnector.getCommittedOffsetCount(mTopicPartition)) .thenReturn(21L); // The second time it's called, it returns 21L because of the first call. Mockito.when( mOffsetTracker.setCommittedOffsetCount(mTopicPartition, 21L)) .thenReturn(20L, 21L); Mockito.when(mOffsetTracker.getLastSeenOffset(mTopicPartition)) .thenReturn(21L); HashSet<LogFilePath> logFilePaths = new HashSet<LogFilePath>(); logFilePaths.add(mLogFilePathWithExtension); Mockito.when(mFileRegistry.getPaths(mTopicPartition)).thenReturn( logFilePaths); FileReader reader = mUploader.getReader(); Mockito.when(reader.next()).thenAnswer(new Answer<KeyValue>() { private int mCallCount = 0; @Override public KeyValue answer(InvocationOnMock invocation) { if (mCallCount == 2) { return null; } return new KeyValue(20 + mCallCount++, null); } }); PowerMockito.mockStatic(IdUtil.class); Mockito.when(IdUtil.getLocalMessageDir()) .thenReturn("some_message_dir"); FileWriter writer = Mockito.mock(FileWriter.class); LogFilePath dstLogFilePath = new LogFilePath( "/some_parent_dir/some_message_dir", "/some_parent_dir/some_message_dir/some_topic/some_partition/" + "some_other_partition/10_0_00000000000000000021.snappy.parquet"); Mockito.when(mFileRegistry.getOrCreateWriter(dstLogFilePath, null)) .thenReturn(writer); mUploader.applyPolicy(false); Mockito.verify(writer).write(Mockito.any(KeyValue.class)); Mockito.verify(mFileRegistry).deletePath(mLogFilePath); }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
testTrimFiles
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
@Override public KeyValue answer(InvocationOnMock invocation) { if (mCallCount == 2) { return null; } return new KeyValue(20 + mCallCount++, null); }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
answer
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
private void mockS3Configs() { Mockito.when(mConfig.getKafkaTopicFilter()).thenReturn("some_topic"); Mockito.when(mConfig.getCloudService()).thenReturn("S3"); Mockito.when(mConfig.getS3Bucket()).thenReturn("some_bucket"); Mockito.when(mConfig.getS3Path()).thenReturn("some_s3_parent_dir"); Mockito.when(mConfig.getOffsetsStorage()).thenReturn(SecorConstants.KAFKA_OFFSETS_STORAGE_ZK); }
UploaderTest tests the log file uploader logic. @author Pawel Garbacki (pawel@pinterest.com)
mockS3Configs
java
pinterest/secor
src/test/java/com/pinterest/secor/uploader/UploaderTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/uploader/UploaderTest.java
Apache-2.0
@Before public void setUp() throws Exception {}
@author Luke Sun (luke.skywalker.sun@gmail.com)
setUp
java
pinterest/secor
src/test/java/com/pinterest/secor/util/BackOffUtilTest.java
https://github.com/pinterest/secor/blob/master/src/test/java/com/pinterest/secor/util/BackOffUtilTest.java
Apache-2.0
@Override public void loadData(Priority priority, final DataCallback<? super InputStream> callback) { Request.Builder requestBuilder = new Request.Builder().url(url.toStringUrl()); for (Map.Entry<String, String> headerEntry : url.getHeaders().entrySet()) { String key = headerEntry.getKey(); requestBuilder.addHeader(key, headerEntry.getValue()); } Request request = requestBuilder.build(); this.callback = callback; call = client.newCall(request); if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O) { call.enqueue(this); } else { try { // Calling execute instead of enqueue is a workaround for #2355, where okhttp throws a // ClassCastException on O. onResponse(call, call.execute()); } catch (IOException e) { onFailure(call, e); } catch (ClassCastException e) { // It's not clear that this catch is necessary, the error may only occur even on O if // enqueue is used. onFailure(call, new IOException("Workaround for framework bug on O", e)); } } }
@author xiaobailong24 @date 2017/8/17 Fetches an {@link InputStream} using the okhttp library.
loadData
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
Apache-2.0
@Override public void onFailure(@NonNull Call call, @NonNull IOException e) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "OkHttp failed to obtain result", e); } callback.onLoadFailed(e); }
@author xiaobailong24 @date 2017/8/17 Fetches an {@link InputStream} using the okhttp library.
onFailure
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
Apache-2.0
@Override public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { responseBody = response.body(); if (response.isSuccessful()) { long contentLength = responseBody.contentLength(); stream = ContentLengthInputStream.obtain(responseBody.byteStream(), contentLength); callback.onDataReady(stream); } else { callback.onLoadFailed(new HttpException(response.message(), response.code())); } }
@author xiaobailong24 @date 2017/8/17 Fetches an {@link InputStream} using the okhttp library.
onResponse
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
Apache-2.0
@Override public void cleanup() { try { if (stream != null) { stream.close(); } } catch (IOException e) { // Ignored } if (responseBody != null) { responseBody.close(); } callback = null; }
@author xiaobailong24 @date 2017/8/17 Fetches an {@link InputStream} using the okhttp library.
cleanup
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
Apache-2.0
@Override public void cancel() { Call local = call; if (local != null) { local.cancel(); } }
@author xiaobailong24 @date 2017/8/17 Fetches an {@link InputStream} using the okhttp library.
cancel
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
Apache-2.0
@NonNull @Override public Class<InputStream> getDataClass() { return InputStream.class; }
@author xiaobailong24 @date 2017/8/17 Fetches an {@link InputStream} using the okhttp library.
getDataClass
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
Apache-2.0
@NonNull @Override public DataSource getDataSource() { return DataSource.REMOTE; }
@author xiaobailong24 @date 2017/8/17 Fetches an {@link InputStream} using the okhttp library.
getDataSource
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpStreamFetcher.java
Apache-2.0
@Override public boolean handles(GlideUrl url) { return true; }
@author xiaobailong24 @date 2017/8/17 A simple model loader for fetching media over http/https using OkHttp.
handles
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpUrlLoader.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpUrlLoader.java
Apache-2.0
@Override public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height, Options options) { return new LoadData<>(model, new OkHttpStreamFetcher(client, model)); }
@author xiaobailong24 @date 2017/8/17 A simple model loader for fetching media over http/https using OkHttp.
buildLoadData
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpUrlLoader.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpUrlLoader.java
Apache-2.0
private static Call.Factory getInternalClient() { if (internalClient == null) { synchronized (Factory.class) { if (internalClient == null) { internalClient = new OkHttpClient(); } } } return internalClient; }
The default factory for {@link OkHttpUrlLoader}s.
getInternalClient
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpUrlLoader.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpUrlLoader.java
Apache-2.0
@Override public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) { return new OkHttpUrlLoader(client); }
Constructor for a new Factory that runs requests using given client. @param client this is typically an instance of {@code OkHttpClient}.
build
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpUrlLoader.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpUrlLoader.java
Apache-2.0
@Override public void teardown() { // Do nothing, this instance doesn't own the client. }
Constructor for a new Factory that runs requests using given client. @param client this is typically an instance of {@code OkHttpClient}.
teardown
java
xiaobailong24/MVVMArms
arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpUrlLoader.java
https://github.com/xiaobailong24/MVVMArms/blob/master/arms/src/main/java/me/xiaobailong24/mvvmarms/http/OkHttpUrlLoader.java
Apache-2.0
@Override public boolean isAdded() { return mFragment != null && mFragment.isAdded(); }
Return true if the fragment is currently added to its activity.
isAdded
java
xiaobailong24/MVVMArms
lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/delegate/FragmentDelegateImpl.java
https://github.com/xiaobailong24/MVVMArms/blob/master/lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/delegate/FragmentDelegateImpl.java
Apache-2.0
@Override public int describeContents() { return 0; }
Return true if the fragment is currently added to its activity.
describeContents
java
xiaobailong24/MVVMArms
lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/delegate/FragmentDelegateImpl.java
https://github.com/xiaobailong24/MVVMArms/blob/master/lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/delegate/FragmentDelegateImpl.java
Apache-2.0
@Override public void writeToParcel(Parcel dest, int flags) { }
Return true if the fragment is currently added to its activity.
writeToParcel
java
xiaobailong24/MVVMArms
lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/delegate/FragmentDelegateImpl.java
https://github.com/xiaobailong24/MVVMArms/blob/master/lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/delegate/FragmentDelegateImpl.java
Apache-2.0
@Override public FragmentDelegateImpl createFromParcel(Parcel source) { return new FragmentDelegateImpl(source); }
Return true if the fragment is currently added to its activity.
createFromParcel
java
xiaobailong24/MVVMArms
lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/delegate/FragmentDelegateImpl.java
https://github.com/xiaobailong24/MVVMArms/blob/master/lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/delegate/FragmentDelegateImpl.java
Apache-2.0
@Override public FragmentDelegateImpl[] newArray(int size) { return new FragmentDelegateImpl[size]; }
Return true if the fragment is currently added to its activity.
newArray
java
xiaobailong24/MVVMArms
lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/delegate/FragmentDelegateImpl.java
https://github.com/xiaobailong24/MVVMArms/blob/master/lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/delegate/FragmentDelegateImpl.java
Apache-2.0
public static <T extends View> T findViewByName(Context context, View view, String viewName) { int id = getResources(context).getIdentifier(viewName, "id", context.getPackageName()); T v = (T) view.findViewById(id); return v; }
findview @param view @param viewName @param <T> @return
findViewByName
java
xiaobailong24/MVVMArms
lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/utils/UiUtils.java
https://github.com/xiaobailong24/MVVMArms/blob/master/lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/utils/UiUtils.java
Apache-2.0
public static <T extends View> T findViewByName(Context context, Activity activity, String viewName) { int id = getResources(context).getIdentifier(viewName, "id", context.getPackageName()); T v = (T) activity.findViewById(id); return v; }
findview @param activity @param viewName @param <T> @return
findViewByName
java
xiaobailong24/MVVMArms
lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/utils/UiUtils.java
https://github.com/xiaobailong24/MVVMArms/blob/master/lifecycle/src/main/java/me/xiaobailong24/mvvmarms/lifecycle/utils/UiUtils.java
Apache-2.0
public static <T> Resource<T> success(@Nullable T data) { return new Resource<>(Status.SUCCESS, data, null); }
@author xiaobailong24 @date 2017/11/22 A generic class that holds a value with its loading status.
success
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
Apache-2.0
public static <T> Resource<T> error(String msg, @Nullable T data) { return new Resource<>(Status.ERROR, data, msg); }
@author xiaobailong24 @date 2017/11/22 A generic class that holds a value with its loading status.
error
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
Apache-2.0
public static <T> Resource<T> loading(@Nullable T data) { return new Resource<>(Status.LOADING, data, null); }
@author xiaobailong24 @date 2017/11/22 A generic class that holds a value with its loading status.
loading
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
Apache-2.0
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Resource<?> resource = (Resource<?>) o; if (status != resource.status) { return false; } if (message != null ? !message.equals(resource.message) : resource.message != null) { return false; } return data != null ? data.equals(resource.data) : resource.data == null; }
@author xiaobailong24 @date 2017/11/22 A generic class that holds a value with its loading status.
equals
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
Apache-2.0
@Override public int hashCode() { int result = status.hashCode(); result = 31 * result + (message != null ? message.hashCode() : 0); result = 31 * result + (data != null ? data.hashCode() : 0); return result; }
@author xiaobailong24 @date 2017/11/22 A generic class that holds a value with its loading status.
hashCode
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
Apache-2.0
@Override public String toString() { return "Resource{" + "status=" + status + ", message='" + message + '\'' + ", data=" + data + '}'; }
@author xiaobailong24 @date 2017/11/22 A generic class that holds a value with its loading status.
toString
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/http/Resource.java
Apache-2.0
public static String decompressToStringForZlib(byte[] bytesToDecompress) { return decompressToStringForZlib(bytesToDecompress, "UTF-8"); }
zlib decompress 2 String @param bytesToDecompress byte[] @return String
decompressToStringForZlib
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
Apache-2.0
public static String decompressToStringForZlib(byte[] bytesToDecompress, String charsetName) { byte[] bytesDecompressed = decompressForZlib(bytesToDecompress); String returnValue = null; try { returnValue = new String(bytesDecompressed, 0, bytesDecompressed.length, charsetName); } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); } return returnValue; }
zlib decompress 2 String @param bytesToDecompress byte[] @param charsetName String @return String
decompressToStringForZlib
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
Apache-2.0
public static byte[] decompressForZlib(byte[] bytesToDecompress) { byte[] returnValues = null; Inflater inflater = new Inflater(); int numberOfBytesToDecompress = bytesToDecompress.length; inflater.setInput(bytesToDecompress, 0, numberOfBytesToDecompress); int numberOfBytesDecompressedSoFar = 0; List<Byte> bytesDecompressedSoFar = new ArrayList<>(); try { while (!inflater.needsInput()) { byte[] bytesDecompressedBuffer = new byte[numberOfBytesToDecompress]; int numberOfBytesDecompressedThisTime = inflater.inflate(bytesDecompressedBuffer); numberOfBytesDecompressedSoFar += numberOfBytesDecompressedThisTime; for (int b = 0; b < numberOfBytesDecompressedThisTime; b++) { bytesDecompressedSoFar.add(bytesDecompressedBuffer[b]); } } returnValues = new byte[bytesDecompressedSoFar.size()]; for (int b = 0; b < returnValues.length; b++) { returnValues[b] = (byte) (bytesDecompressedSoFar.get(b)); } } catch (DataFormatException dfe) { dfe.printStackTrace(); } inflater.end(); return returnValues; }
zlib decompress 2 byte @param bytesToDecompress byte[] @return byte[]
decompressForZlib
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
Apache-2.0
public static byte[] compressForZlib(byte[] bytesToCompress) { Deflater deflater = new Deflater(); deflater.setInput(bytesToCompress); deflater.finish(); byte[] bytesCompressed = new byte[Short.MAX_VALUE]; int numberOfBytesAfterCompression = deflater.deflate(bytesCompressed); byte[] returnValues = new byte[numberOfBytesAfterCompression]; System.arraycopy(bytesCompressed, 0, returnValues, 0, numberOfBytesAfterCompression); return returnValues; }
zlib compress 2 byte @param bytesToCompress byte[] @return byte[]
compressForZlib
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
Apache-2.0
public static byte[] compressForZlib(String stringToCompress) { byte[] returnValues = null; try { returnValues = compressForZlib(stringToCompress.getBytes("UTF-8")); } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); } return returnValues; }
zlib compress 2 byte @param stringToCompress String @return byte[]
compressForZlib
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
Apache-2.0
public static byte[] compressForGzip(String string) { ByteArrayOutputStream os = null; GZIPOutputStream gos = null; try { os = new ByteArrayOutputStream(string.length()); gos = new GZIPOutputStream(os); gos.write(string.getBytes("UTF-8")); return os.toByteArray(); } catch (IOException e) { e.printStackTrace(); } finally { closeQuietly(gos); closeQuietly(os); } return null; }
gzip compress 2 byte @param string String @return byte[]
compressForGzip
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
Apache-2.0
public static String decompressForGzip(byte[] compressed) { return decompressForGzip(compressed, "UTF-8"); }
gzip decompress 2 string @param compressed byte[] @return String
decompressForGzip
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
Apache-2.0
public static String decompressForGzip(byte[] compressed, String charsetName) { final int BUFFER_SIZE = compressed.length; GZIPInputStream gis = null; ByteArrayInputStream is = null; try { is = new ByteArrayInputStream(compressed); gis = new GZIPInputStream(is, BUFFER_SIZE); StringBuilder string = new StringBuilder(); byte[] data = new byte[BUFFER_SIZE]; int bytesRead; while ((bytesRead = gis.read(data)) != -1) { string.append(new String(data, 0, bytesRead, charsetName)); } return string.toString(); } catch (IOException e) { e.printStackTrace(); } finally { closeQuietly(gis); closeQuietly(is); } return null; }
gzip decompress 2 string @param compressed byte[] @param charsetName String @return String
decompressForGzip
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
Apache-2.0
public static void closeQuietly(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (RuntimeException rethrown) { throw rethrown; } catch (Exception ignored) { } } }
gzip decompress 2 string @param compressed byte[] @param charsetName String @return String
closeQuietly
java
xiaobailong24/MVVMArms
repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
https://github.com/xiaobailong24/MVVMArms/blob/master/repository/src/main/java/me/xiaobailong24/mvvmarms/repository/utils/ZipHelper.java
Apache-2.0
@Test public void useAppContext() throws Exception { // Context of the app under test. Context appContext = InstrumentationRegistry.getTargetContext(); assertEquals("me.xiaobailong24.mvvmarms.weather", appContext.getPackageName()); }
Instrumentation test, which will execute on an Android device. @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
useAppContext
java
xiaobailong24/MVVMArms
weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/ExampleInstrumentedTest.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/ExampleInstrumentedTest.java
Apache-2.0
@Override public void onSubscribe(Subscription s) { s.request(Integer.MAX_VALUE); }
@author xiaobailong24 @date 2017/7/30 Room Database Test {@link me.xiaobailong24.mvvmarms.weather.mvvm.model.db.WeatherNowDao}
onSubscribe
java
xiaobailong24/MVVMArms
weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
Apache-2.0
@Override public void onError(Throwable t) { Log.e(TAG, "onError: ", t); }
@author xiaobailong24 @date 2017/7/30 Room Database Test {@link me.xiaobailong24.mvvmarms.weather.mvvm.model.db.WeatherNowDao}
onError
java
xiaobailong24/MVVMArms
weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
Apache-2.0
@Override public void onComplete() { }
@author xiaobailong24 @date 2017/7/30 Room Database Test {@link me.xiaobailong24.mvvmarms.weather.mvvm.model.db.WeatherNowDao}
onComplete
java
xiaobailong24/MVVMArms
weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
Apache-2.0
@Override public void onSubscribe(Subscription s) { s.request(Integer.MAX_VALUE); }
@author xiaobailong24 @date 2017/7/30 Room Database Test {@link me.xiaobailong24.mvvmarms.weather.mvvm.model.db.WeatherNowDao}
onSubscribe
java
xiaobailong24/MVVMArms
weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
Apache-2.0
@Override public void onError(Throwable t) { Log.e(TAG, "onError: ", t); }
@author xiaobailong24 @date 2017/7/30 Room Database Test {@link me.xiaobailong24.mvvmarms.weather.mvvm.model.db.WeatherNowDao}
onError
java
xiaobailong24/MVVMArms
weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
Apache-2.0
@Override public void onComplete() { }
@author xiaobailong24 @date 2017/7/30 Room Database Test {@link me.xiaobailong24.mvvmarms.weather.mvvm.model.db.WeatherNowDao}
onComplete
java
xiaobailong24/MVVMArms
weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/androidTest/java/me/xiaobailong24/mvvmarms/weather/db/WeatherNowDaoTest.java
Apache-2.0
@Override public Fragment getItem(int position) { return mFragments.get(position); }
@author xiaobailong24 @date 2017/8/15 ViewPager Adapter for Fragment
getItem
java
xiaobailong24/MVVMArms
weather/src/main/java/me/xiaobailong24/mvvmarms/weather/mvvm/view/adapter/WeatherPagerAdapter.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/main/java/me/xiaobailong24/mvvmarms/weather/mvvm/view/adapter/WeatherPagerAdapter.java
Apache-2.0
@Override public int getCount() { return mFragments.size(); }
@author xiaobailong24 @date 2017/8/15 ViewPager Adapter for Fragment
getCount
java
xiaobailong24/MVVMArms
weather/src/main/java/me/xiaobailong24/mvvmarms/weather/mvvm/view/adapter/WeatherPagerAdapter.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/main/java/me/xiaobailong24/mvvmarms/weather/mvvm/view/adapter/WeatherPagerAdapter.java
Apache-2.0
@Override public CharSequence getPageTitle(int position) { return mTitles.get(position); }
@author xiaobailong24 @date 2017/8/15 ViewPager Adapter for Fragment
getPageTitle
java
xiaobailong24/MVVMArms
weather/src/main/java/me/xiaobailong24/mvvmarms/weather/mvvm/view/adapter/WeatherPagerAdapter.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/main/java/me/xiaobailong24/mvvmarms/weather/mvvm/view/adapter/WeatherPagerAdapter.java
Apache-2.0
@Override public boolean canChildScrollUp() { if (mScrollUpChild != null) { return ViewCompat.canScrollVertically(mScrollUpChild, -1); } return super.canChildScrollUp(); }
@author xiaobailong24 @date 2017/7/31 Extends {@link SwipeRefreshLayout} to support non-direct descendant scrolling views. <p> {@link SwipeRefreshLayout} works as expected when a scroll view is a direct child: it triggers the refresh only when the view is on top. This class adds a way (@link #setScrollUpChild} to define which view controls this behavior.
canChildScrollUp
java
xiaobailong24/MVVMArms
weather/src/main/java/me/xiaobailong24/mvvmarms/weather/mvvm/view/weight/ScrollChildSwipeRefreshLayout.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/main/java/me/xiaobailong24/mvvmarms/weather/mvvm/view/weight/ScrollChildSwipeRefreshLayout.java
Apache-2.0
public void setScrollUpChild(View view) { mScrollUpChild = view; }
@author xiaobailong24 @date 2017/7/31 Extends {@link SwipeRefreshLayout} to support non-direct descendant scrolling views. <p> {@link SwipeRefreshLayout} works as expected when a scroll view is a direct child: it triggers the refresh only when the view is on top. This class adds a way (@link #setScrollUpChild} to define which view controls this behavior.
setScrollUpChild
java
xiaobailong24/MVVMArms
weather/src/main/java/me/xiaobailong24/mvvmarms/weather/mvvm/view/weight/ScrollChildSwipeRefreshLayout.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/main/java/me/xiaobailong24/mvvmarms/weather/mvvm/view/weight/ScrollChildSwipeRefreshLayout.java
Apache-2.0
@Test public void addition_isCorrect() throws Exception { assertEquals(4, 2 + 2); }
Example local unit test, which will execute on the development machine (host). @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
addition_isCorrect
java
xiaobailong24/MVVMArms
weather/src/test/java/me/xiaobailong24/mvvmarms/weather/ExampleUnitTest.java
https://github.com/xiaobailong24/MVVMArms/blob/master/weather/src/test/java/me/xiaobailong24/mvvmarms/weather/ExampleUnitTest.java
Apache-2.0
private void printServiceUrls(MesosCluster cluster) { // print independent from roles variables String masterContainer = cluster.getMaster().getContainerId(); String gateway = String.format("export %s=%s", MesosCluster.TOKEN_NETWORK_GATEWAY, DockerContainersUtil.getGatewayIpAddress(masterContainer)); output.println(gateway); List<ClusterProcess> uniqueMembers = ClusterUtil.getDistinctRoleProcesses(cluster.getMemberProcesses()); for (ClusterProcess process : uniqueMembers) { URI serviceUrl = process.getServiceUrl(); if (serviceUrl != null) { String service = String.format("export %s%s=%s", MesosCluster.MINIMESOS_TOKEN_PREFIX, process.getRole().toUpperCase(), serviceUrl.toString()); String serviceIp = String.format("export %s%s_IP=%s", MesosCluster.MINIMESOS_TOKEN_PREFIX, process.getRole().toUpperCase(), serviceUrl.getHost()); output.println(String.format("%s; %s", service, serviceIp)); } } if (Environment.isRunningInDockerOnMac()) { output.println("You are running Docker on Mac so use localhost instead of container IPs for Master, Marathon, Zookeepr and Consul"); } }
Prints cluster services URLs and IPs @param cluster to examine
printServiceUrls
java
ContainerSolutions/minimesos
cli/src/main/java/com/containersol/minimesos/main/CommandInfo.java
https://github.com/ContainerSolutions/minimesos/blob/master/cli/src/main/java/com/containersol/minimesos/main/CommandInfo.java
Apache-2.0
@Override public boolean validateParameters() { return true; }
Prints cluster services URLs and IPs @param cluster to examine
validateParameters
java
ContainerSolutions/minimesos
cli/src/main/java/com/containersol/minimesos/main/CommandInfo.java
https://github.com/ContainerSolutions/minimesos/blob/master/cli/src/main/java/com/containersol/minimesos/main/CommandInfo.java
Apache-2.0
@Override public String getName() { return CLINAME; }
Prints cluster services URLs and IPs @param cluster to examine
getName
java
ContainerSolutions/minimesos
cli/src/main/java/com/containersol/minimesos/main/CommandInfo.java
https://github.com/ContainerSolutions/minimesos/blob/master/cli/src/main/java/com/containersol/minimesos/main/CommandInfo.java
Apache-2.0