|
| 1 | +package testing.saker.sipka.jvm.tailrec; |
| 2 | + |
| 3 | +import java.io.InputStream; |
| 4 | +import java.util.Map; |
| 5 | +import java.util.TreeMap; |
| 6 | +import java.util.zip.ZipEntry; |
| 7 | +import java.util.zip.ZipInputStream; |
| 8 | + |
| 9 | +import saker.build.file.path.SakerPath; |
| 10 | +import saker.build.thirdparty.saker.util.classloader.ClassLoaderDataFinder; |
| 11 | +import saker.build.thirdparty.saker.util.classloader.MultiDataClassLoader; |
| 12 | +import saker.build.thirdparty.saker.util.io.ByteArrayRegion; |
| 13 | +import saker.build.thirdparty.saker.util.io.ByteSource; |
| 14 | +import saker.build.thirdparty.saker.util.io.StreamUtils; |
| 15 | +import testing.saker.SakerTest; |
| 16 | +import testing.saker.build.tests.TestUtils; |
| 17 | +import testing.saker.nest.util.NestRepositoryCachingEnvironmentTestCase; |
| 18 | + |
| 19 | +@SakerTest |
| 20 | +public class RepackageArchiveOptimizeSakerTest extends NestRepositoryCachingEnvironmentTestCase{ |
| 21 | + |
| 22 | + @Override |
| 23 | + protected void runNestTaskTestImpl() throws Throwable { |
| 24 | + // TODO Auto-generated method stub |
| 25 | + CombinedTargetTaskResult res = runScriptTask("build"); |
| 26 | + SakerPath outpath = (SakerPath) res.getTargetTaskResult("secondpath"); |
| 27 | + |
| 28 | + Map<String, ByteArrayRegion> resourceBytes = new TreeMap<>(); |
| 29 | + try (InputStream is = ByteSource.toInputStream(files.openInput(outpath)); |
| 30 | + ZipInputStream zis = new ZipInputStream(is)) { |
| 31 | + for (ZipEntry entry; (entry = zis.getNextEntry()) != null;) { |
| 32 | + resourceBytes.put(entry.getName(), StreamUtils.readStreamFully(zis)); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + try (ClassLoaderDataFinder jarfinder = new TestUtils.MemoryClassLoaderDataFinder(resourceBytes)) { |
| 37 | + MultiDataClassLoader cl = new MultiDataClassLoader(jarfinder); |
| 38 | + Class<?> c = Class.forName("test.Main", false, cl); |
| 39 | + //this should succeed, as it was optimized |
| 40 | + c.getMethod("count", int.class).invoke(null, 10000000); |
| 41 | + } |
| 42 | + |
| 43 | + runScriptTask("build"); |
| 44 | + assertEmpty(getMetric().getRunTaskIdResults()); |
| 45 | + } |
| 46 | + |
| 47 | +} |
0 commit comments