-
Notifications
You must be signed in to change notification settings - Fork 626
Implement backend discovery. #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ort-backend-cct/src/main/java/com/google/android/datatransport/cct/CctBackendFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2018 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.android.datatransport.cct; | ||
|
||
import android.support.annotation.Keep; | ||
import android.support.annotation.VisibleForTesting; | ||
import com.google.android.datatransport.runtime.backends.BackendFactory; | ||
import com.google.android.datatransport.runtime.backends.CreationContext; | ||
import com.google.android.datatransport.runtime.backends.TransportBackend; | ||
|
||
@Keep | ||
public class CctBackendFactory implements BackendFactory { | ||
private static final String URL = mergeStrings("hts/pa.ogepscmlgbth", "tp:/lygolai.o/o/ac"); | ||
vkryachko marked this conversation as resolved.
Show resolved
Hide resolved
vkryachko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Override | ||
public TransportBackend create(CreationContext creationContext) { | ||
return new CctTransportBackend( | ||
URL, creationContext.getWallClock(), creationContext.getMonotonicClock()); | ||
} | ||
|
||
@VisibleForTesting | ||
static String mergeStrings(String part1, String part2) { | ||
int sizeDiff = part1.length() - part2.length(); | ||
if (sizeDiff < 0 || sizeDiff > 1) { | ||
throw new IllegalArgumentException("Invalid input received"); | ||
} | ||
|
||
StringBuilder url = new StringBuilder(part1.length() + part2.length()); | ||
|
||
for (int i = 0; i < part1.length(); i++) { | ||
url.append(part1.charAt(i)); | ||
if (part2.length() > i) { | ||
url.append(part2.charAt(i)); | ||
} | ||
} | ||
|
||
return url.toString(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...backend-cct/src/test/java/com/google/android/datatransport/cct/CctBackendFactoryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2018 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.android.datatransport.cct; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public class CctBackendFactoryTest { | ||
@Test | ||
public void mergeStrings_whenPartsAreUnequalLength() { | ||
String part1 = "hts/eapecm"; | ||
String part2 = "tp:/xml.o"; | ||
assertThat(CctBackendFactory.mergeStrings(part1, part2)).isEqualTo("https://example.com"); | ||
} | ||
|
||
@Test | ||
public void mergeStrings_whenPartsAreEqualLength() { | ||
String part1 = "hts/eape.o"; | ||
String part2 = "tp:/xmlscm"; | ||
assertThat(CctBackendFactory.mergeStrings(part1, part2)).isEqualTo("https://examples.com"); | ||
} | ||
|
||
@Test | ||
public void mergeStrings_whenPart2IsLongerThanPart1() { | ||
String part1 = "135"; | ||
String part2 = "2467"; | ||
assertThrows( | ||
IllegalArgumentException.class, () -> CctBackendFactory.mergeStrings(part1, part2)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
...sport-runtime/src/main/java/com/google/android/datatransport/runtime/BackendRegistry.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ntime/src/main/java/com/google/android/datatransport/runtime/backends/BackendFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2018 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.android.datatransport.runtime.backends; | ||
|
||
/** Used by backend discovery to create {@link TransportBackend}s. */ | ||
vkryachko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public interface BackendFactory { | ||
ashwinraghav marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TransportBackend create(CreationContext creationContext); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.